From 6fd77a96b4117b7210ecd5fab1a6304cb3ebc976 Mon Sep 17 00:00:00 2001 From: Eugene Popov Date: Fri, 21 Apr 2023 15:41:13 +0300 Subject: FilterBar: improve keyboard behavior and tab ordering With this MR, when the filterbar has the keyboard focus: - pressing the Tab key moves the keyboard focus to the view - pressing the Down, PageDown, Up and PageUp keys moves the focus to the view and emulate pressing the same key in it (you can navigate directly from the filterbar) --- src/filterbar/filterbar.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/filterbar/filterbar.cpp') diff --git a/src/filterbar/filterbar.cpp b/src/filterbar/filterbar.cpp index 76e23d420..e24025c5b 100644 --- a/src/filterbar/filterbar.cpp +++ b/src/filterbar/filterbar.cpp @@ -10,6 +10,7 @@ #include +#include #include #include #include @@ -47,6 +48,9 @@ FilterBar::FilterBar(QWidget *parent) hLayout->addWidget(m_lockButton); hLayout->addWidget(m_filterInput); hLayout->addWidget(closeButton); + + setTabOrder(m_lockButton, closeButton); + setTabOrder(closeButton, m_filterInput); } FilterBar::~FilterBar() @@ -96,10 +100,8 @@ void FilterBar::showEvent(QShowEvent *event) } } -void FilterBar::keyReleaseEvent(QKeyEvent *event) +void FilterBar::keyPressEvent(QKeyEvent *event) { - QWidget::keyReleaseEvent(event); - switch (event->key()) { case Qt::Key_Escape: if (m_filterInput->text().isEmpty()) { @@ -107,14 +109,28 @@ void FilterBar::keyReleaseEvent(QKeyEvent *event) } else { m_filterInput->clear(); } - break; + return; case Qt::Key_Enter: case Qt::Key_Return: Q_EMIT focusViewRequest(); - break; + return; + + case Qt::Key_Down: + case Qt::Key_PageDown: + case Qt::Key_Up: + case Qt::Key_PageUp: { + Q_EMIT focusViewRequest(); + QWidget *focusWidget = QApplication::focusWidget(); + if (focusWidget && focusWidget != this) { + QApplication::sendEvent(focusWidget, event); + } + return; + } default: break; } + + QWidget::keyPressEvent(event); } -- cgit v1.3