@@ -160,6 +160,11 @@ void DockFocusControllerPrivate::updateDockWidgetFocus(CDockWidget* DockWidget)
160160 }
161161#endif
162162
163+ if (old == DockWidget)
164+ {
165+ return ;
166+ }
167+
163168 if (DockWidget->isVisible ())
164169 {
165170 emit DockManager->focusedDockWidgetChanged (old, DockWidget);
@@ -212,6 +217,8 @@ void CDockFocusController::onApplicationFocusChanged(QWidget* focusedOld, QWidge
212217 return ;
213218 }
214219
220+ // qDebug() << "\n----------------------------";
221+ // qDebug() << "CDockFocusController::onApplicationFocusChanged " << " old: " << focusedOld << " new: " << focusedNow;
215222 Q_UNUSED (focusedOld)
216223 if (!focusedNow)
217224 {
@@ -223,6 +230,14 @@ void CDockFocusController::onApplicationFocusChanged(QWidget* focusedOld, QWidge
223230 if (DockWidgetTab)
224231 {
225232 DockWidget = DockWidgetTab->dockWidget ();
233+ // If the DockWidgetTab "steals" the focus from a widget in the same
234+ // DockWidget, then we immediately give the focus back to the previous
235+ // focused widget focusedOld
236+ if (DockWidget == d->FocusedDockWidget && focusedOld && focusedOld != focusedNow)
237+ {
238+ focusedOld->setFocus ();
239+ return ;
240+ }
226241 }
227242
228243 if (!DockWidget)
@@ -278,7 +293,8 @@ void CDockFocusController::onFocusedDockAreaViewToggled(bool Open)
278293 return ;
279294 }
280295
281- CDockManager::setWidgetFocus (OpenedDockAreas[0 ]->currentDockWidget ()->tabWidget ());
296+ // CDockManager::setWidgetFocus(OpenedDockAreas[0]->currentDockWidget()->tabWidget());
297+ d->updateDockWidgetFocus (OpenedDockAreas[0 ]->currentDockWidget ());
282298}
283299
284300
@@ -293,7 +309,8 @@ void CDockFocusController::notifyWidgetOrAreaRelocation(QWidget* DroppedWidget)
293309 CDockWidget* DockWidget = qobject_cast<CDockWidget*>(DroppedWidget);
294310 if (DockWidget)
295311 {
296- CDockManager::setWidgetFocus (DockWidget->tabWidget ());
312+ // CDockManager::setWidgetFocus(DockWidget->tabWidget());
313+ d->updateDockWidgetFocus (DockWidget);
297314 return ;
298315 }
299316
@@ -304,7 +321,8 @@ void CDockFocusController::notifyWidgetOrAreaRelocation(QWidget* DroppedWidget)
304321 }
305322
306323 DockWidget = DockArea->currentDockWidget ();
307- CDockManager::setWidgetFocus (DockWidget->tabWidget ());
324+ // CDockManager::setWidgetFocus(DockWidget->tabWidget());
325+ d->updateDockWidgetFocus (DockWidget);
308326}
309327
310328
@@ -325,8 +343,11 @@ void CDockFocusController::notifyFloatingWidgetDrop(CFloatingDockContainer* Floa
325343 auto DockWidget = vDockWidget.value <CDockWidget*>();
326344 if (DockWidget)
327345 {
346+ d->FocusedDockWidget = nullptr ;
328347 DockWidget->dockAreaWidget ()->setCurrentDockWidget (DockWidget);
329- CDockManager::setWidgetFocus (DockWidget->tabWidget ());
348+ // CDockManager::setWidgetFocus(DockWidget->tabWidget());
349+ // qDebug() << "CDockFocusController::notifyFloatingWidgetDrop";
350+ d->updateDockWidgetFocus (DockWidget);
330351 }
331352}
332353
0 commit comments