diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-04-24 11:41:05 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-04-29 20:31:52 +0000 |
commit | f2347077f503d103974636cae9319d127714e2e4 (patch) | |
tree | 2134b29ccc8e21c2fd6962c0d34fa3e1bbadbbe4 /src/widgets/widgets | |
parent | e9b8837c31041326a0e4d66eed6775d385913915 (diff) |
Always open a text control's context menu on the same screen
It's very disorienting when a context menu pops up on a different
screen from where the right mouse button was clicked.
QWidgetPrivate::setScreenForPoint() can give incorrect results in
multi-screen desktop configurations; but we can give the menu a hint
by setting initialScreenIndex, which was originally used only when
QDesktopScreen or QDesktopScreenWidget is the parent (see
b3fc5e1ea3eb4fe838ac716aaca4efaa5de5a814 ).
Task-number: QTBUG-76162
Pick-to: 5.15
Pick-to: 5.12
Change-Id: Icd4abdc32564430147e6c63a8ea70d483d25cddd
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/widgets')
-rw-r--r-- | src/widgets/widgets/qwidgettextcontrol.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index e32f779bb0..b87b4e54fa 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -58,6 +58,7 @@ #include "private/qapplication_p.h" #include "private/qtextdocumentlayout_p.h" #include "private/qabstracttextdocumentlayout_p.h" +#include "private/qmenu_p.h" #include "qtextdocument.h" #include "private/qtextdocument_p.h" #include "qtextlist.h" @@ -1943,6 +1944,10 @@ void QWidgetTextControlPrivate::contextMenuEvent(const QPoint &screenPos, const if (!menu) return; menu->setAttribute(Qt::WA_DeleteOnClose); + if (auto *window = static_cast<QWidget *>(parent)->window()->windowHandle()) { + QMenuPrivate::get(menu)->topData()->initialScreenIndex = + QGuiApplication::screens().indexOf(window->screen()); + } menu->popup(screenPos); #endif } |