diff options
author | Liang Qi <liang.qi@qt.io> | 2016-05-20 13:46:21 +0200 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> | 2016-05-23 21:09:46 +0200 |
commit | 56d6e000f7487c59172330ebd23a718268c508f1 (patch) | |
tree | 1494432583b1569816075091a8075b31d795f77c /src/widgets/widgets/qmenubar.cpp | |
parent | 9fd407fc6a29c94b4568dd042a05c208255179e0 (diff) | |
parent | c276aa51303b7c6f8e4cd854aadf8344a906e50f (diff) |
Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
mkspecs/wince80colibri-armv7-msvc2012/qmake.conf
qmake/generators/win32/msvc_vcproj.cpp
src/corelib/global/qnamespace.h
src/corelib/global/qnamespace.qdoc
src/corelib/io/qfsfileengine_win.cpp
src/corelib/tools/tools.pri
src/network/ssl/qsslconfiguration_p.h
src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp
src/plugins/platforms/windows/windows.pri
src/src.pro
src/tools/bootstrap/bootstrap.pro
src/tools/uic/cpp/cppwriteinitialization.cpp
src/widgets/dialogs/qfilesystemmodel.cpp
tests/auto/testlib/selftests/expected_cmptest.teamcity
tests/auto/testlib/selftests/expected_cmptest.txt
Change-Id: I4d2ac78f0dcc97f008186bbbc769c6fe588ab0e5
Diffstat (limited to 'src/widgets/widgets/qmenubar.cpp')
-rw-r--r-- | src/widgets/widgets/qmenubar.cpp | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp index 59cf9c9aee..3a90e14655 100644 --- a/src/widgets/widgets/qmenubar.cpp +++ b/src/widgets/widgets/qmenubar.cpp @@ -698,7 +698,6 @@ void QMenuBarPrivate::init() if (platformMenuBar) q->hide(); q->setBackgroundRole(QPalette::Button); - oldWindow = oldParent = 0; handleReparent(); q->setMouseTracking(q->style()->styleHint(QStyle::SH_MenuBar_MouseTracking, 0, q)); @@ -1320,30 +1319,41 @@ void QMenuBarPrivate::handleReparent() { Q_Q(QMenuBar); QWidget *newParent = q->parentWidget(); - //Note: if parent is reparented, then window may change even if parent doesn't - // we need to install an event filter on parent, and remove the old one - - if (oldParent != newParent) { - if (oldParent) - oldParent->removeEventFilter(q); - if (newParent) - newParent->installEventFilter(q); + //Note: if parent is reparented, then window may change even if parent doesn't. + // We need to install an avent filter on each parent up to the parent that is + // also a window (for shortcuts) + QWidget *newWindow = newParent ? newParent->window() : Q_NULLPTR; + + QVector<QPointer<QWidget> > newParents; + // Remove event filters on ex-parents, keep them on still-parents + // The parents are always ordered in the vector + foreach (const QPointer<QWidget> &w, oldParents) { + if (w) { + if (newParent == w) { + newParents.append(w); + if (newParent != newWindow) //stop at the window + newParent = newParent->parentWidget(); + } else { + w->removeEventFilter(q); + } + } } - //we also need event filter on top-level (for shortcuts) - QWidget *newWindow = newParent ? newParent->window() : 0; - - if (oldWindow != newWindow) { - if (oldParent && oldParent != oldWindow) - oldWindow->removeEventFilter(q); - - if (newParent && newParent != newWindow) - newWindow->installEventFilter(q); + // At this point, newParent is the next one to be added to newParents + while (newParent && newParent != newWindow) { + //install event filters all the way up to (excluding) the window + newParents.append(newParent); + newParent->installEventFilter(q); + newParent = newParent->parentWidget(); } - oldParent = newParent; - oldWindow = newWindow; + if (newParent && newWindow) { + // Install the event filter on the window + newParents.append(newParent); + newParent->installEventFilter(q); + } + oldParents = newParents; if (platformMenuBar) { if (newWindow) { @@ -1450,10 +1460,9 @@ bool QMenuBar::event(QEvent *e) bool QMenuBar::eventFilter(QObject *object, QEvent *event) { Q_D(QMenuBar); - if (object == parent() && object) { - if (event->type() == QEvent::ParentChange) //GrandparentChange + if (object && (event->type() == QEvent::ParentChange)) //GrandparentChange d->handleReparent(); - } + if (object == d->leftWidget || object == d->rightWidget) { switch (event->type()) { case QEvent::ShowToParent: |