Workaround Qt bug which broke the focus chain

Focusing a tab widget would focus an hidden tab bar, which makes
the propagation stop

Fixes #180
This commit is contained in:
Sergio Martins
2021-04-30 15:59:27 +01:00
parent affb48f44d
commit 8ab8e0524b
3 changed files with 26 additions and 0 deletions

View File

@@ -140,6 +140,27 @@ bool TabBarWidget::dragCanStart(QPoint pressPos, QPoint pos) const
return false;
}
bool TabBarWidget::event(QEvent *ev)
{
// Qt has a bug in QWidgetPrivate::deepestFocusProxy(), it doesn't honour visibility
// of the focus scope. Once an hidden widget is focused the the chain is broken and tab
// stops working (#180)
auto parent = parentWidget();
if (!parent)
return QTabBar::event(ev);
const bool result = QTabBar::event(ev);
if (ev->type() == QEvent::Show) {
parent->setFocusProxy(this);
} else if (ev->type() == QEvent::Hide) {
parent->setFocusProxy(nullptr);
}
return result;
}
QString TabBarWidget::text(int index) const
{
return tabText(index);