From a4efbfbfa69f04ed21fe703a11bb59416ef8a821 Mon Sep 17 00:00:00 2001 From: Felix Ernst Date: Fri, 26 Jan 2024 19:12:23 +0100 Subject: Fix focus chain Prior to this commit pressing Tab repeatedly would bring the focus to the end of the status bar but not further. This commit makes sure the tab focus doesn't get stuck on the invisible tab bar by explicitly removing the DolphinTabBar from the focus chain while it is hidden. I don't understand why pressing Tab doesn't do anything for the invisible tab bar, but removing an invisible and currently useless widget from the focus chain seems sensible in any case. Improve the accessibility autotest to prevent regressions concerning this. --- src/dolphintabbar.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/dolphintabbar.cpp') diff --git a/src/dolphintabbar.cpp b/src/dolphintabbar.cpp index 55b5e5edf..4c918e611 100644 --- a/src/dolphintabbar.cpp +++ b/src/dolphintabbar.cpp @@ -13,6 +13,28 @@ #include #include +class PreventFocusWhileHidden : public QObject +{ +public: + PreventFocusWhileHidden(QObject *parent) + : QObject(parent){}; + +protected: + bool eventFilter(QObject *obj, QEvent *ev) override + { + switch (ev->type()) { + case QEvent::Hide: + static_cast(obj)->setFocusPolicy(Qt::NoFocus); + return false; + case QEvent::Show: + static_cast(obj)->setFocusPolicy(Qt::TabFocus); + return false; + default: + return false; + } + }; +}; + DolphinTabBar::DolphinTabBar(QWidget *parent) : QTabBar(parent) , m_autoActivationIndex(-1) @@ -23,6 +45,9 @@ DolphinTabBar::DolphinTabBar(QWidget *parent) setMovable(true); setTabsClosable(true); + setFocusPolicy(Qt::NoFocus); + installEventFilter(new PreventFocusWhileHidden(this)); + m_autoActivationTimer = new QTimer(this); m_autoActivationTimer->setSingleShot(true); m_autoActivationTimer->setInterval(800); -- cgit v1.3