QDockWidget: Propagate window title when re-docking

When a floating dockwidget's title changes, it is rendered as a
window title. When the title changes while floating, the change will be
reverted to the pre-change title when the dockwidget is docked again.

This patch explicitly propagates the window title, if it has been
programmatically changed while the dock widget is floating.

It adds test functionality in tst_QDockWidget::floatingTabs().

Fixes: QTBUG-113591
Change-Id: I96fa69fb27ad1a85f4ea9ce44c0a22290259fca6
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit c153066baa)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Axel Spoerl 2023-05-16 10:40:13 +02:00 committed by Qt Cherry-pick Bot
parent d1bef7ea9a
commit 78760fd3d8
2 changed files with 24 additions and 5 deletions

View File

@ -1186,10 +1186,10 @@ void QDockWidgetPrivate::setWindowState(bool floating, bool unplug, const QRect
return; // this dockwidget can't be redocked
}
bool wasFloating = q->isFloating();
const bool wasFloating = q->isFloating();
if (wasFloating) // Prevent repetitive unplugging from nested invocations (QTBUG-42818)
unplug = false;
bool hidden = q->isHidden();
const bool hidden = q->isHidden();
if (q->isVisible())
q->hide();
@ -1497,8 +1497,14 @@ void QDockWidget::changeEvent(QEvent *event)
QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(this->layout());
switch (event->type()) {
case QEvent::ModifiedChange:
case QEvent::WindowTitleChange:
if (isFloating() && windowHandle() && d->topData()) {
// From QWidget::setWindowTitle(): Propagate window title without signal emission
d->topData()->caption = windowHandle()->title();
d->setWindowTitle_helper(windowHandle()->title());
}
Q_FALLTHROUGH();
case QEvent::ModifiedChange:
update(layout->titleArea());
#ifndef QT_NO_ACTION
d->fixedWindowTitle = qt_setWindowTitle_helperHelper(windowTitle(), this);

View File

@ -65,7 +65,7 @@ private slots:
// Dock area permissions for DockWidgets and DockWidgetGroupWindows
void dockPermissions();
// test floating tabs and item_tree consistency
// test floating tabs, item_tree and window title consistency
void floatingTabs();
// test hide & show
@ -1375,7 +1375,10 @@ void tst_QDockWidget::floatingTabs()
/*
* replug both dock widgets into their initial position
* expected behavior: both docks are plugged and no longer floating
* expected behavior:
- both docks are plugged
- both docks are no longer floating
- title changes have been propagated
*/
@ -1396,6 +1399,12 @@ void tst_QDockWidget::floatingTabs()
QTRY_VERIFY(d1->isFloating());
QTRY_VERIFY(!d2->isFloating());
// Change titles
static constexpr QLatin1StringView newD1("New D1");
static constexpr QLatin1StringView newD2("New D2");
d1->setWindowTitle(newD1);
d2->setWindowTitle(newD2);
// Plug back into dock areas
qCDebug(lcTestDockWidget) << "*** test plugging back to dock areas ***";
qCDebug(lcTestDockWidget) << "Move d1 to left dock";
@ -1415,6 +1424,10 @@ void tst_QDockWidget::floatingTabs()
QTRY_VERIFY(!mainWindow->findChild<QDockWidgetGroupWindow*>());
QTRY_VERIFY(ftabs.isNull());
// check window titles
QCOMPARE(d1->windowTitle(), newD1);
QCOMPARE(d2->windowTitle(), newD2);
// Check if paths are consistent
qCDebug(lcTestDockWidget) << "Checking path consistency" << layout->layoutState.indexOf(d1) << layout->layoutState.indexOf(d2);