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>
This commit is contained in:
Thorbjørn Lund Martsum 2017-08-25 12:46:51 +02:00
parent 01ea60fdd2
commit 9ad0e09f5b
2 changed files with 20 additions and 0 deletions

View File

@ -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

View File

@ -447,6 +447,7 @@ public:
bool hasMouseMoved(const QPoint &globalPos);
void adjustMenuScreen(const QPoint &p);
void updateLayoutDirection();
//menu fading/scrolling effects