diff options
author | Liang Qi <liang.qi@qt.io> | 2017-09-20 11:37:26 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-09-20 11:58:32 +0200 |
commit | 01bc69f99f189b03d0b9cad77cc300798937cad1 (patch) | |
tree | 730f3b691cfc1830ec617b3c2ad8df16180de724 /src/widgets/widgets/qmenu.cpp | |
parent | c23c4a921d0e9e2d18a62af82d38ca27eac7bcb3 (diff) | |
parent | 6d699d08200b1fe3a616dfbc275d46c98b77fcbd (diff) |
Merge remote-tracking branch 'origin/5.9' into 5.10
Conflicts:
src/plugins/styles/mac/qmacstyle_mac.mm
src/widgets/util/qcompleter.cpp
src/widgets/widgets/qmainwindowlayout.cpp
src/widgets/widgets/qmdisubwindow.cpp
Change-Id: If0e96981af07ce36ac68f2e69211bc2120f93973
Diffstat (limited to 'src/widgets/widgets/qmenu.cpp')
-rw-r--r-- | src/widgets/widgets/qmenu.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index c1fb409380..ded218de73 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -39,8 +39,6 @@ #include "qmenu.h" -#ifndef QT_NO_MENU - #include <QtWidgets/private/qtwidgetsglobal_p.h> #include "qdebug.h" @@ -856,6 +854,24 @@ void QMenuPrivate::_q_overrideMenuActionDestroyed() menuAction=defaultMenuAction; } +void QMenuPrivate::adjustMenuScreen(const QPoint &p) +{ + Q_Q(QMenu); + // The windowHandle must point to the screen where the menu will be shown. + // The (item) size calculations depend on the menu screen, + // so a wrong screen would often cause wrong sizes (on high DPI) + const QScreen *primaryScreen = QApplication::primaryScreen(); + const QScreen *currentScreen = q->windowHandle() ? q->windowHandle()->screen() : primaryScreen; + const int screenNumberForPoint = QApplication::desktop()->screenNumber(p); + QScreen *actualScreen = QGuiApplication::screens().at(screenNumberForPoint); + if (actualScreen && currentScreen != actualScreen) { + if (!q->windowHandle()) // Try to create a window handle if not created. + createWinId(); + if (q->windowHandle()) + q->windowHandle()->setScreen(actualScreen); + itemsDirty = true; + } +} void QMenuPrivate::updateLayoutDirection() { @@ -2321,6 +2337,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction) d->motions = 0; d->doChildEffects = true; d->updateLayoutDirection(); + d->adjustMenuScreen(p); #if QT_CONFIG(menubar) // if this menu is part of a chain attached to a QMenuBar, set the @@ -3766,5 +3783,3 @@ QT_END_NAMESPACE // for private slots #include "moc_qmenu.cpp" #include "qmenu.moc" - -#endif // QT_NO_MENU |