Always open a submenu on the same screen where the parent menu is
We've seen submenus opening on different screens in different scenarios, but probably there's never a sensible reason to do that. QWidgetPrivate::setScreenForPoint() can often give incorrect results in multi-screen desktop configurations; this is a way of avoiding that. Task-number: QTBUG-76162 Change-Id: I895696c6858ad953258c84b21117beea4c4fc01d Reviewed-by: Andy Shaw <andy.shaw@qt.io>
This commit is contained in:
parent
89dc1a1865
commit
c068edcecf
@ -40,6 +40,7 @@
|
||||
#include "qmenu.h"
|
||||
|
||||
#include <QtWidgets/private/qtwidgetsglobal_p.h>
|
||||
#include <QtWidgets/private/qwidgetwindow_p.h>
|
||||
|
||||
#include "qdebug.h"
|
||||
#include "qstyle.h"
|
||||
@ -2343,15 +2344,23 @@ void QMenuPrivate::popup(const QPoint &p, QAction *atAction, PositionFunction po
|
||||
// Use d->popupScreen to remember, because initialScreenIndex will be reset after the first showing.
|
||||
// However if eventLoop exists, then exec() already did this by calling createWinId(); so leave it alone. (QTBUG-76162)
|
||||
if (!eventLoop) {
|
||||
bool screenSet = false;
|
||||
const int screenIndex = topData()->initialScreenIndex;
|
||||
if (screenIndex >= 0)
|
||||
popupScreen = screenIndex;
|
||||
if (auto s = QGuiApplication::screens().value(popupScreen)) {
|
||||
if (setScreen(s))
|
||||
itemsDirty = true;
|
||||
} else if (setScreenForPoint(p)) {
|
||||
itemsDirty = true;
|
||||
screenSet = true;
|
||||
} else if (QMenu *parentMenu = qobject_cast<QMenu *>(parent)) {
|
||||
// a submenu is always opened from an open parent menu,
|
||||
// so show it on the same screen where the parent is. (QTBUG-76162)
|
||||
if (setScreen(QMenuPrivate::get(parentMenu)->windowHandle()->screen()))
|
||||
itemsDirty = true;
|
||||
screenSet = true;
|
||||
}
|
||||
if (!screenSet && setScreenForPoint(p))
|
||||
itemsDirty = true;
|
||||
}
|
||||
|
||||
const bool contextMenu = isContextMenu();
|
||||
|
Loading…
x
Reference in New Issue
Block a user