From e760d3e96752a6609f49272d3056073020294af7 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Thu, 14 May 2020 09:06:04 +0200 Subject: [PATCH] Improved focus handling when dropping a dock widget --- src/DockAreaWidget.cpp | 2 +- src/DockWidgetTab.cpp | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index a6e6f1f..33aecbc 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -413,6 +413,7 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget, bool Activate) { d->ContentsLayout->insertWidget(index, DockWidget); + DockWidget->setDockArea(this); DockWidget->tabWidget()->setDockAreaWidget(this); auto TabWidget = DockWidget->tabWidget(); // Inserting the tab will change the current index which in turn will @@ -428,7 +429,6 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget, { setCurrentIndex(index); } - DockWidget->setDockArea(this); d->updateTitleBarButtonStates(); } diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index 167b2d7..c907ee0 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -463,15 +463,21 @@ void CDockWidgetTab::setActiveTab(bool active) bool AllTabsHaveCloseButton = d->testConfigFlag(CDockManager::AllTabsHaveCloseButton); bool TabHasCloseButton = (ActiveTabHasCloseButton && active) | AllTabsHaveCloseButton; d->CloseButton->setVisible(DockWidgetClosable && TabHasCloseButton); - if (d->IsActiveTab == active) - { - return; - } + bool UpdateFocusStyle = false; if (active && !hasFocus()) { - std::cout << "setFocus(Qt::OtherFocusReason);" << std::endl; setFocus(Qt::OtherFocusReason); + UpdateFocusStyle = true; + } + + if (d->IsActiveTab == active) + { + if (UpdateFocusStyle) + { + updateStyle(); + } + return; } d->IsActiveTab = active; updateStyle();