QMenu: Corner case size fix (high DPI + multi screen)

We always need to set the QMenu screen explicit also when
it is about to be shown on the primary screen.
The reason is QWidget::metric (called from style/sizeHint)
may use qApp->devicePixelRatioF() when it does not
know about the topLevelWindow. That may not be the same
value as DPR on primary screen. It can be argued that
it likely is a bug in QWidget::metric, but fixing that
looks to be a somewhat dangerous behavior change.

Task-number: QTBUG-59794
Change-Id: I6ed0e808aa31bee5b77c0e19ce61a77548fdbb38
Reviewed-by: Morten Kristensen <msk@nullpointer.dk>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
This commit is contained in:
Thorbjørn Lund Martsum 2017-11-21 08:46:57 +01:00
parent 203fb83803
commit fb880bbdff

View File

@ -853,8 +853,7 @@ void QMenuPrivate::adjustMenuScreen(const QPoint &p)
// 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 QScreen *currentScreen = q->windowHandle() ? q->windowHandle()->screen() : nullptr;
const int screenNumberForPoint = QApplication::desktop()->screenNumber(p);
QScreen *actualScreen = QGuiApplication::screens().at(screenNumberForPoint);
if (actualScreen && currentScreen != actualScreen) {