QMdiArea: Fix top level window title when using DontMaximizeSubWindowOnActivation
When trying to find the original window title, check for another maximized sub window and use its title. Protect the calls to setWindowTitle to prevent the original title from being cleared. Pick-to: 6.1 5.15 Fixes: QTBUG-92240 Change-Id: I55175382ab261b4cf8b5528304adaaec4fbe2c31 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
f8c1d339ec
commit
8886462872
@ -263,11 +263,28 @@ static inline ControlElement<T> *ptr(QWidget *widget)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QString QMdiSubWindowPrivate::originalWindowTitleHelper() const
|
||||
{
|
||||
Q_Q(const QMdiSubWindow);
|
||||
// QTBUG-92240: When DontMaximizeSubWindowOnActivation is set and
|
||||
// there is another subwindow maximized, use its original title.
|
||||
if (auto *mdiArea = q->mdiArea()) {
|
||||
const auto &subWindows = mdiArea->subWindowList();
|
||||
for (auto *subWindow : subWindows) {
|
||||
if (subWindow != q && subWindow->isMaximized()) {
|
||||
auto *subWindowD = static_cast<QMdiSubWindowPrivate *>(qt_widget_private(subWindow));
|
||||
if (!subWindowD->originalTitle.isNull())
|
||||
return subWindowD->originalTitle;
|
||||
}
|
||||
}
|
||||
}
|
||||
return q->window()->windowTitle();
|
||||
}
|
||||
|
||||
QString QMdiSubWindowPrivate::originalWindowTitle()
|
||||
{
|
||||
Q_Q(QMdiSubWindow);
|
||||
if (originalTitle.isNull()) {
|
||||
originalTitle = q->window()->windowTitle();
|
||||
originalTitle = originalWindowTitleHelper();
|
||||
if (originalTitle.isNull())
|
||||
originalTitle = QLatin1String("");
|
||||
}
|
||||
@ -282,11 +299,17 @@ void QMdiSubWindowPrivate::setNewWindowTitle()
|
||||
return;
|
||||
QString original = originalWindowTitle();
|
||||
if (!original.isEmpty()) {
|
||||
if (!original.contains(QMdiSubWindow::tr("- [%1]").arg(childTitle)))
|
||||
q->window()->setWindowTitle(QMdiSubWindow::tr("%1 - [%2]").arg(original, childTitle));
|
||||
if (!original.contains(QMdiSubWindow::tr("- [%1]").arg(childTitle))) {
|
||||
auto title = QMdiSubWindow::tr("%1 - [%2]").arg(original, childTitle);
|
||||
ignoreWindowTitleChange = true;
|
||||
q->window()->setWindowTitle(title);
|
||||
ignoreWindowTitleChange = false;
|
||||
}
|
||||
|
||||
} else {
|
||||
ignoreWindowTitleChange = true;
|
||||
q->window()->setWindowTitle(childTitle);
|
||||
ignoreWindowTitleChange = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -286,6 +286,7 @@ public:
|
||||
#endif
|
||||
void updateInternalWindowTitle();
|
||||
QString originalWindowTitle();
|
||||
QString originalWindowTitleHelper() const;
|
||||
void setNewWindowTitle();
|
||||
|
||||
inline int titleBarHeight() const
|
||||
|
@ -1,4 +1,4 @@
|
||||
/****************************************************************************
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
@ -281,6 +281,8 @@ private slots:
|
||||
void nativeSubWindows();
|
||||
void task_209615();
|
||||
void task_236750();
|
||||
void qtbug92240_title_data();
|
||||
void qtbug92240_title();
|
||||
|
||||
private:
|
||||
QMdiSubWindow *activeWindow;
|
||||
@ -2697,6 +2699,45 @@ void tst_QMdiArea::task_236750()
|
||||
subWindow->showMinimized();
|
||||
}
|
||||
|
||||
// QTBUG-92240: When subwindows are maximized, their title is supposed to
|
||||
// appear on the main window. When DontMaximizeSubWindowOnActivation was set,
|
||||
// titles of previously created maximized windows interfered, resulting in
|
||||
// "QTBUG-92240 - [1] - [2]".
|
||||
void tst_QMdiArea::qtbug92240_title_data()
|
||||
{
|
||||
QTest::addColumn<bool>("dontMaximize");
|
||||
QTest::newRow("default") << false;
|
||||
QTest::newRow("dontMaximize") << true;
|
||||
}
|
||||
|
||||
void tst_QMdiArea::qtbug92240_title()
|
||||
{
|
||||
QFETCH(bool, dontMaximize);
|
||||
|
||||
#ifdef Q_OS_MACOS
|
||||
QSKIP("Not supported on macOS");
|
||||
#endif
|
||||
|
||||
QMainWindow w;
|
||||
const QString title = QStringLiteral("QTBUG-92240");
|
||||
w.setWindowTitle(title);
|
||||
w.menuBar()->addMenu(QStringLiteral("File"));
|
||||
w.show();
|
||||
|
||||
auto *mdiArea = new QMdiArea;
|
||||
w.setCentralWidget(mdiArea);
|
||||
if (dontMaximize)
|
||||
mdiArea->setOption(QMdiArea::DontMaximizeSubWindowOnActivation);
|
||||
auto *sw1 = mdiArea->addSubWindow(new QWidget);
|
||||
sw1->setWindowTitle(QStringLiteral("1"));
|
||||
sw1->showMaximized();
|
||||
QTRY_COMPARE(w.windowTitle(), QLatin1String("QTBUG-92240 - [1]"));
|
||||
auto *sw2 = mdiArea->addSubWindow(new QWidget);
|
||||
sw2->setWindowTitle(QStringLiteral("2"));
|
||||
sw2->showMaximized();
|
||||
QTRY_COMPARE(w.windowTitle(), QLatin1String("QTBUG-92240 - [2]"));
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QMdiArea)
|
||||
#include "tst_qmdiarea.moc"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user