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)
#include <KLocalizedString>
#include <KLocalizedString>
#include <QHBoxLayout>
#include <QKeyEvent>
#include <QLineEdit>
#include <QHBoxLayout>
#include <QKeyEvent>
#include <QLineEdit>
hLayout->addWidget(m_lockButton);
hLayout->addWidget(m_filterInput);
hLayout->addWidget(closeButton);
hLayout->addWidget(m_lockButton);
hLayout->addWidget(m_filterInput);
hLayout->addWidget(closeButton);
+
+ setTabOrder(m_lockButton, closeButton);
+ setTabOrder(closeButton, m_filterInput);
}
FilterBar::~FilterBar()
}
FilterBar::~FilterBar()
-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()) {
switch (event->key()) {
case Qt::Key_Escape:
if (m_filterInput->text().isEmpty()) {
} else {
m_filterInput->clear();
}
} else {
m_filterInput->clear();
}
case Qt::Key_Enter:
case Qt::Key_Return:
Q_EMIT focusViewRequest();
case Qt::Key_Enter:
case Qt::Key_Return:
Q_EMIT focusViewRequest();
+ 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;
+ }
+
+ QWidget::keyPressEvent(event);
protected:
void showEvent(QShowEvent *event) override;
protected:
void showEvent(QShowEvent *event) override;
- void keyReleaseEvent(QKeyEvent *event) override;
+ void keyPressEvent(QKeyEvent *event) override;
private:
QLineEdit *m_filterInput;
private:
QLineEdit *m_filterInput;