From 2cdc94e15cd5cd111b3104fea6b36063cc2dc50a Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 9 Mar 2024 19:04:02 +0100 Subject: [PATCH] Gui: Fix using context-menu of ExpressionLineEdit If for the DlgExpressionInput the user config parameter 'NoSystemBsckground' is set to True it's not used as a normal dialog but as a pop-up window. In this mode the context-menu of the ExpressionLineEdit isn't working. A previous commit (a3036d16f1de) fixed a crash but not this issue. For Qt4 DlgExpressionInput has overridden the eventFilter() to handle using the context-menu but this is not working any more for Qt5 or Qt6. Luckily, it has appeared that with Qt5 and Qt6 it works out-of-the box now and the event filter is not needed any more. --- src/Gui/DlgExpressionInput.cpp | 32 -------------------------------- src/Gui/DlgExpressionInput.h | 3 --- 2 files changed, 35 deletions(-) diff --git a/src/Gui/DlgExpressionInput.cpp b/src/Gui/DlgExpressionInput.cpp index ff93a60adc..a2d8a7cf91 100644 --- a/src/Gui/DlgExpressionInput.cpp +++ b/src/Gui/DlgExpressionInput.cpp @@ -90,8 +90,6 @@ DlgExpressionInput::DlgExpressionInput(const App::ObjectIdentifier & _path, #endif setAttribute(Qt::WA_NoSystemBackground, true); setAttribute(Qt::WA_TranslucentBackground, true); - - qApp->installEventFilter(this); } else { ui->expression->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); @@ -109,7 +107,6 @@ DlgExpressionInput::DlgExpressionInput(const App::ObjectIdentifier & _path, DlgExpressionInput::~DlgExpressionInput() { - qApp->removeEventFilter(this); delete ui; } @@ -282,34 +279,5 @@ void DlgExpressionInput::show() ui->expression->selectAll(); } -void DlgExpressionInput::showEvent(QShowEvent* ev) -{ - QDialog::showEvent(ev); -} - -bool DlgExpressionInput::eventFilter(QObject *obj, QEvent *ev) -{ - // if the user clicks on a widget different to this - if (ev->type() == QEvent::MouseButtonPress && obj != this) { - // Since the widget has a transparent background we cannot rely - // on the size of the widget. Instead, it must be checked if the - // cursor is on this or an underlying widget or outside. - if (!underMouse()) { - // if the expression fields context-menu is open do not close the dialog - auto menu = qobject_cast(obj); - if (menu && menu->parentWidget() == ui->expression) { - return false; - } - bool on = ui->expression->completerActive(); - // Do this only if the completer is not shown - if (!on) { - qApp->removeEventFilter(this); - reject(); - } - } - } - return false; -} - #include "moc_DlgExpressionInput.cpp" diff --git a/src/Gui/DlgExpressionInput.h b/src/Gui/DlgExpressionInput.h index 180cdf2000..8bad8ae59f 100644 --- a/src/Gui/DlgExpressionInput.h +++ b/src/Gui/DlgExpressionInput.h @@ -76,13 +76,10 @@ public: QPoint expressionPosition() const; void setExpressionInputSize(int width, int height); - bool eventFilter(QObject *obj, QEvent *event) override; - public Q_SLOTS: void show(); protected: - void showEvent(QShowEvent*) override; void mouseReleaseEvent(QMouseEvent*) override; void mousePressEvent(QMouseEvent*) override;