aboutsummaryrefslogtreecommitdiff
path: root/src/mainwindow
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-05-27 18:39:41 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-05-27 18:39:41 +0200
commitd8481551d623f6f19e359805b5ad6fbd28356ed2 (patch)
treef71eea3253fd9718ab178f3804371f6e6404ac42 /src/mainwindow
parentBack/Forward menu shortcuts (diff)
downloadsmolbote-d8481551d623f6f19e359805b5ad6fbd28356ed2.tar.xz
Focus view when changing tabs
Diffstat (limited to 'src/mainwindow')
-rw-r--r--src/mainwindow/widgets/tabwidget.cpp7
-rw-r--r--src/mainwindow/window.cpp19
2 files changed, 14 insertions, 12 deletions
diff --git a/src/mainwindow/widgets/tabwidget.cpp b/src/mainwindow/widgets/tabwidget.cpp
index 66182c3..97c2717 100644
--- a/src/mainwindow/widgets/tabwidget.cpp
+++ b/src/mainwindow/widgets/tabwidget.cpp
@@ -25,6 +25,13 @@ TabWidget::TabWidget(QWidget *parent)
connect(this, &TabWidget::tabCloseRequested, this, &TabWidget::deleteTab);
+ // when changing tabs, give focus to the widget
+ // otherwise when closing tabs, the tabwidget will retain focus
+ connect(this, &TabWidget::currentChanged, this, [this](int index) {
+ if(widget(index))
+ widget(index)->setFocus();
+ });
+
// context menu
tabContextMenu = new QMenu(this);
auto *closeTab = tabContextMenu->addAction(tr("Close Tab"));
diff --git a/src/mainwindow/window.cpp b/src/mainwindow/window.cpp
index 055d945..0c28663 100644
--- a/src/mainwindow/window.cpp
+++ b/src/mainwindow/window.cpp
@@ -14,6 +14,7 @@
#include <QToolButton>
#include <QStyle>
#include <QAction>
+#include <QShortcut>
#include <QMenu>
#include <QJsonObject>
#include <QJsonArray>
@@ -55,26 +56,20 @@ Window::Window(const QHash<QString, QString> &config, QWidget *parent, Qt::Windo
tabWidget->setCornerWidget(newTab_button, Qt::TopRightCorner);
// general actions
- auto *closeTab_action = new QAction(this);
- closeTab_action->setShortcut(QKeySequence(config.value("window.shortcuts.close")));
- connect(closeTab_action, &QAction::triggered, this, [=]() {
+ auto *closeTab_shortcut = new QShortcut(QKeySequence(config.value("window.shortcuts.close")), this);
+ connect(closeTab_shortcut, &QShortcut::activated, this, [=]() {
tabWidget->deleteTab(tabWidget->currentIndex());
});
- addAction(closeTab_action);
- auto *leftTab_action = new QAction(this);
- leftTab_action->setShortcut(QKeySequence(config.value("window.shortcuts.left")));
- connect(leftTab_action, &QAction::triggered, this, [=]() {
+ auto *leftTab_shortcut = new QShortcut(QKeySequence(config.value("window.shortcuts.left")), this);
+ connect(leftTab_shortcut, &QShortcut::activated, this, [=]() {
tabWidget->setCurrentIndex(qMax(0, tabWidget->currentIndex() - 1));
});
- addAction(leftTab_action);
- auto *rightTab_action = new QAction(this);
- rightTab_action->setShortcut(QKeySequence(config.value("window.shortcuts.right")));
- connect(rightTab_action, &QAction::triggered, this, [=]() {
+ auto *rightTab_shortcut = new QShortcut(QKeySequence(config.value("window.shortcuts.right")), this);
+ connect(rightTab_shortcut, &QShortcut::activated, this, [=]() {
tabWidget->setCurrentIndex(qMin(tabWidget->currentIndex() + 1, tabWidget->count() - 1));
});
- addAction(rightTab_action);
connect(tabWidget, &TabWidget::currentChanged, [this](int index) {
if(index < 0) {