File tree Expand file tree Collapse file tree 3 files changed +16
-7
lines changed
Expand file tree Collapse file tree 3 files changed +16
-7
lines changed Original file line number Diff line number Diff line change 11#include " buttonpopup.h"
22
33#include < QWidgetAction>
4+ #include < QKeyEvent>
45
56#include < utils/widgetutils.h>
67
@@ -17,6 +18,17 @@ ButtonPopup::ButtonPopup(QToolButton *p_btn, QWidget *p_parent)
1718#endif
1819}
1920
21+ void ButtonPopup::keyPressEvent (QKeyEvent *p_event)
22+ {
23+ const int key = p_event->key ();
24+ if (key == Qt::Key_Return || key == Qt::Key_Enter) {
25+ // Swallow Enter/Return key here to avoid hiding the popup.
26+ p_event->accept ();
27+ return ;
28+ }
29+ QMenu::keyPressEvent (p_event);
30+ }
31+
2032void ButtonPopup::addWidget (QWidget *p_widget)
2133{
2234 auto act = new QWidgetAction (this );
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ namespace vnotex
1515 ButtonPopup (QToolButton *p_btn, QWidget *p_parent = nullptr );
1616
1717 protected:
18+ void keyPressEvent (QKeyEvent *p_event) override ;
19+
1820 void addWidget (QWidget *p_widget);
1921
2022 // Button for this menu.
Original file line number Diff line number Diff line change @@ -48,6 +48,8 @@ void TagViewer::setupUI()
4848 m_searchLineEdit->setToolTip (tr (" [Shift+Enter] to add current selected tag in the list" ));
4949 connect (m_searchLineEdit, &QLineEdit::textChanged,
5050 this , &TagViewer::searchAndFilter);
51+ connect (m_searchLineEdit, &QLineEdit::returnPressed,
52+ this , &TagViewer::handleSearchLineEditReturnPressed);
5153 mainLayout->addWidget (m_searchLineEdit);
5254
5355 auto tagNameValidator = new QRegularExpressionValidator (QRegularExpression (" [^>]*" ), m_searchLineEdit);
@@ -88,13 +90,6 @@ bool TagViewer::eventFilter(QObject *p_obj, QEvent *p_event)
8890 m_searchLineEdit->setFocus ();
8991 }
9092 return true ;
91- } else if (key == Qt::Key_Return || key == Qt::Key_Enter) {
92- if (p_obj == m_searchLineEdit) {
93- // Pressing twice will make the popup hide if we use the signal returnPressed,
94- // so we handle it here earlier.
95- handleSearchLineEditReturnPressed ();
96- return true ;
97- }
9893 }
9994 }
10095
You can’t perform that action at this time.
0 commit comments