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 ++++++++++ src/MainWindow.h | 4 ++++ 2 files changed, 14 insertions(+) (limited to 'src') 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() { diff --git a/src/MainWindow.h b/src/MainWindow.h index 1664f849..bb23ff11 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -69,6 +69,8 @@ public: protected: void closeEvent(QCloseEvent *event); bool event(QEvent *event) override; + // HACK: https://bugreports.qt.io/browse/QTBUG-83972, qtwayland cannot auto hide menu + void mousePressEvent(QMouseEvent *) override; private slots: //! Handle interaction with the tray icon. @@ -77,6 +79,8 @@ private slots: virtual void setWindowTitle(int notificationCount); signals: + // HACK: https://bugreports.qt.io/browse/QTBUG-83972, qtwayland cannot auto hide menu + void hideMenu(); void reload(); void secretsChanged(); -- cgit 1.5.1