diff options
-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 |