From 7d95ac23cecdec48b3c84a42afdfbed5b6d870a8 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Mon, 23 Jan 2023 20:15:43 +0800 Subject: feat: hide all popup menus when press leftbutton on somewhere else Log: according to the bug on https://bugreports.qt.io/browse/QTBUG-83972, The menu will always stay if not click one of the item. So I try to make a hack for it, wait qt solve it someday --- src/MainWindow.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/MainWindow.cpp') diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index dcb4be49..5c92fb5b 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -359,6 +359,16 @@ MainWindow::event(QEvent *event) return QQuickView::event(event); } +// HACK: https://bugreports.qt.io/browse/QTBUG-83972, qtwayland cannot auto hide menu +void +MainWindow::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + emit hideMenu(); + } + return QQuickView::mousePressEvent(event); +} + void MainWindow::restoreWindowSize() { -- cgit 1.5.1 From c893dfd102c6cf07aa7d10d461d5e2ca81034310 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Thu, 26 Jan 2023 20:34:38 +0800 Subject: chore: limit it to linux wayland --- src/MainWindow.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/MainWindow.cpp') diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 5c92fb5b..3fedbdc0 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -363,9 +363,13 @@ MainWindow::event(QEvent *event) void MainWindow::mousePressEvent(QMouseEvent *event) { - if (event->button() == Qt::LeftButton) { - emit hideMenu(); +#if defined(Q_OS_LINUX) + if (QGuiApplication::platformName() == "wayland") { + if (event->button() == Qt::LeftButton) { + emit hideMenu(); + } } +#endif return QQuickView::mousePressEvent(event); } -- cgit 1.5.1 From e84e2b0aaa7e97c578fd5eede4e4201ef0e220aa Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Sat, 28 Jan 2023 17:10:45 +0800 Subject: chore: remove button check --- src/MainWindow.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/MainWindow.cpp') diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 3fedbdc0..8c2b4c35 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -365,9 +365,7 @@ MainWindow::mousePressEvent(QMouseEvent *event) { #if defined(Q_OS_LINUX) if (QGuiApplication::platformName() == "wayland") { - if (event->button() == Qt::LeftButton) { - emit hideMenu(); - } + emit hideMenu(); } #endif return QQuickView::mousePressEvent(event); -- cgit 1.5.1