Add Ctrl+K shortcut for focusing search text

This commit is contained in:
Christoffer Klang 2013-08-11 00:47:41 +02:00
parent 22cfff3e69
commit a4125be39f
2 changed files with 13 additions and 0 deletions

View File

@ -108,6 +108,9 @@ MainWindow::MainWindow(QWidget *parent) :
// initialise ui // initialise ui
ui->setupUi(this); ui->setupUi(this);
setupShortcuts();
restoreGeometry(settings.value("geometry").toByteArray()); restoreGeometry(settings.value("geometry").toByteArray());
ui->splitter->restoreState(settings.value("splitter").toByteArray()); ui->splitter->restoreState(settings.value("splitter").toByteArray());
connect(ui->splitter, &QSplitter::splitterMoved, [=](int, int) { connect(ui->splitter, &QSplitter::splitterMoved, [=](int, int) {
@ -434,6 +437,15 @@ void MainWindow::bringToFront(bool withHack)
#endif #endif
} }
void MainWindow::setupShortcuts()
{
QShortcut* focusSearch = new QShortcut(QKeySequence("Ctrl+K"), this);
focusSearch->setContext(Qt::ApplicationShortcut);
connect(focusSearch, &QShortcut::activated, [=]() {
ui->lineEdit->setFocus();
});
}
void MainWindow::setHotKey(const QKeySequence& hotKey_) { void MainWindow::setHotKey(const QKeySequence& hotKey_) {
// platform-specific code for global key grabbing // platform-specific code for global key grabbing
#ifdef WIN32 #ifdef WIN32

View File

@ -51,6 +51,7 @@ protected:
settings.setValue("geometry", saveGeometry()); settings.setValue("geometry", saveGeometry());
QMainWindow::closeEvent(event); QMainWindow::closeEvent(event);
} }
void setupShortcuts();
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H