QMenu size fix - Mark items dirty on screen change

It seems like an optimization on the itemsDirty flag
caused a bug to be re-introduced. When a popup is shown
on a new screen, the itemsDirty must however be set to
ensure that new correct sizes are calculated.

Task-number: QTBUG-59794
Change-Id: Ifb5c233b1f9d4d38bd0cd7a9a71cc32ad3212f8c
Reviewed-by: Morten Kristensen <msk@nullpointer.dk>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
This commit is contained in:
Thorbjørn Lund Martsum 2019-05-22 09:32:05 +02:00
parent d661a22ae2
commit 48f7f65dc3
3 changed files with 12 additions and 6 deletions

View File

@ -2580,14 +2580,15 @@ void QWidgetPrivate::createWinId()
/*! /*!
\internal \internal
Ensures that the widget is set on the screen point is on. This is handy getting a correct Ensures that the widget is set on the screen point is on. This is handy getting a correct
size hint before a resize in e.g QMenu and QToolTip size hint before a resize in e.g QMenu and QToolTip.
Returns if the screen was changed.
*/ */
void QWidgetPrivate::setScreenForPoint(const QPoint &pos) bool QWidgetPrivate::setScreenForPoint(const QPoint &pos)
{ {
Q_Q(QWidget); Q_Q(QWidget);
if (!q->isWindow()) if (!q->isWindow())
return; return false;
// Find the screen for pos and make the widget undertand it is on that screen. // Find the screen for pos and make the widget undertand it is on that screen.
const QScreen *currentScreen = windowHandle() ? windowHandle()->screen() : nullptr; const QScreen *currentScreen = windowHandle() ? windowHandle()->screen() : nullptr;
QScreen *actualScreen = QGuiApplication::screenAt(pos); QScreen *actualScreen = QGuiApplication::screenAt(pos);
@ -2596,7 +2597,9 @@ void QWidgetPrivate::setScreenForPoint(const QPoint &pos)
createWinId(); createWinId();
if (windowHandle()) if (windowHandle())
windowHandle()->setScreen(actualScreen); windowHandle()->setScreen(actualScreen);
return true;
} }
return false;
} }
/*! /*!

View File

@ -355,7 +355,7 @@ public:
void createRecursively(); void createRecursively();
void createWinId(); void createWinId();
void setScreenForPoint(const QPoint &pos); bool setScreenForPoint(const QPoint &pos);
void createTLExtra(); void createTLExtra();
void createExtra(); void createExtra();

View File

@ -73,6 +73,7 @@
#endif #endif
#include "qpushbutton.h" #include "qpushbutton.h"
#include "qtooltip.h" #include "qtooltip.h"
#include <qwindow.h>
#include <private/qpushbutton_p.h> #include <private/qpushbutton_p.h>
#include <private/qaction_p.h> #include <private/qaction_p.h>
#include <private/qguiapplication_p.h> #include <private/qguiapplication_p.h>
@ -2356,8 +2357,10 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
d->motions = 0; d->motions = 0;
d->doChildEffects = true; d->doChildEffects = true;
d->updateLayoutDirection(); d->updateLayoutDirection();
// Ensure that we get correct sizeHints by placing this window on the right screen.
d->setScreenForPoint(p); // Ensure that we get correct sizeHints by placing this window on the correct screen.
if (d->setScreenForPoint(p))
d->itemsDirty = true;
const bool contextMenu = d->isContextMenu(); const bool contextMenu = d->isContextMenu();
if (d->lastContextMenu != contextMenu) { if (d->lastContextMenu != contextMenu) {