diff options
author | Thorbjørn Lund Martsum <tmartsum@gmail.com> | 2017-08-25 12:46:51 +0200 |
---|---|---|
committer | Thorbjørn Lund Martsum <tmartsum@gmail.com> | 2017-09-13 06:35:40 +0000 |
commit | 9ad0e09f5bbaab8ced2ea6bb175bbd13935413cf (patch) | |
tree | 0fa77d8cbc1ab7b540114c594efb93bb6ce39f83 /src/widgets | |
parent | 01ea60fdd2cb0b0f0ffc45ec7fba84ef2a7dff00 (diff) |
QMenu: Fix size on high DPI + multi screen
When calculating item sizes (used for menu size)
the styles consider the widget screen. This widget
screen could be a wrong default or an obsolete value.
This patch ensures the screen is correct set on popup.
[ChangeLog][QtWidgets][QMenu] Fixed menu size issue when
using high DPI on multi-screen system.
Task-number: QTBUG-59794
Change-Id: I84461441d5d33cb8dc04ab1acb9630fbfc8c5514
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Morten Kristensen <msk@nullpointer.dk>
Reviewed-by: Per Liboriussen <liborius@chelys.dk>
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/widgets/qmenu.cpp | 19 | ||||
-rw-r--r-- | src/widgets/widgets/qmenu_p.h | 1 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 0a5c52abe6..38f53f089d 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -849,6 +849,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() { @@ -2313,6 +2331,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 diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index 65975da984..c24080e42e 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -447,6 +447,7 @@ public: bool hasMouseMoved(const QPoint &globalPos); + void adjustMenuScreen(const QPoint &p); void updateLayoutDirection(); //menu fading/scrolling effects |