Commit 12055d69 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Give keyboard focus to the search input field when showing dialog

Previously, the Help button got the keyboard focus because the focus
chain is messed up because the button box is created before the
page.

GnuPG-bug-id: 6095
parent d5471b7c
......@@ -25,6 +25,7 @@
#include <Libkleo/DocAction>
#include <QDialogButtonBox>
#include <QLineEdit>
#include <QPushButton>
#include <QScrollArea>
......@@ -34,6 +35,7 @@ class GroupsConfigDialog::Private
GroupsConfigDialog *const q;
GroupsConfigPage *configPage = nullptr;
bool initialFocusWasSet = false;
public:
Private(GroupsConfigDialog *qq)
......@@ -48,6 +50,21 @@ public:
saveLayout();
}
void setInitialFocus()
{
if (initialFocusWasSet) {
return;
}
// this is a bit hacky, but fixing the focus chain where the dialog
// button box comes before the page, which causes the first button in
// the button box to be focussed initially, is even more hacky
Q_ASSERT(configPage->findChildren<QLineEdit *>().size() == 1);
if (auto searchField = configPage->findChild<QLineEdit *>()) {
searchField->setFocus();
}
initialFocusWasSet = true;
}
private:
void saveLayout()
{
......@@ -125,6 +142,8 @@ QString GroupsConfigDialog::dialogName()
void GroupsConfigDialog::showEvent(QShowEvent *event)
{
d->setInitialFocus();
KConfigDialog::showEvent(event);
// prevent accidental closing of dialog when pressing Enter while the search field has focus
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment