summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/widgets/qdockarealayout.cpp3
-rw-r--r--tests/auto/qmainwindow/tst_qmainwindow.cpp41
2 files changed, 43 insertions, 1 deletions
diff --git a/src/gui/widgets/qdockarealayout.cpp b/src/gui/widgets/qdockarealayout.cpp
index e83e97e..12f4569 100644
--- a/src/gui/widgets/qdockarealayout.cpp
+++ b/src/gui/widgets/qdockarealayout.cpp
@@ -3321,7 +3321,8 @@ void QDockAreaLayout::keepSize(QDockWidget *w)
void QDockAreaLayout::styleChangedEvent()
{
sep = mainWindow->style()->pixelMetric(QStyle::PM_DockWidgetSeparatorExtent, 0, mainWindow);
- fitLayout();
+ if (isValid())
+ fitLayout();
}
QT_END_NAMESPACE
diff --git a/tests/auto/qmainwindow/tst_qmainwindow.cpp b/tests/auto/qmainwindow/tst_qmainwindow.cpp
index b4d765c..4eb3c22 100644
--- a/tests/auto/qmainwindow/tst_qmainwindow.cpp
+++ b/tests/auto/qmainwindow/tst_qmainwindow.cpp
@@ -140,6 +140,7 @@ private slots:
void saveState();
void restoreState();
void restoreStateFromPreviousVersion();
+ void restoreStateDockWidgetBug();
void createPopupMenu();
void iconSizeChanged();
void toolButtonStyleChanged();
@@ -1285,6 +1286,46 @@ void tst_QMainWindow::restoreState()
QVERIFY(mw.restoreState(state, 1));
}
+/*
+ QWidget::setStylesheet() generates QEvent::StyleChange event, which will
+ cause the function QDockAreaLayout::fitLayout() to be called before the layout
+ of MainWindow is activated. This will force the size of dock widgets
+ and the central widget to be calculated using the wrong geometry, which will
+ break the state restored by QMainWindow::restoreState().
+*/
+void tst_QMainWindow::restoreStateDockWidgetBug()
+{
+ QByteArray state;
+
+ //save state
+ {
+ QMainWindow mw1;
+ QDockWidget *dw1 = new QDockWidget();
+ dw1->setObjectName("Left DockWidget");
+ mw1.addDockWidget(Qt::LeftDockWidgetArea, dw1);
+ mw1.setCentralWidget(new QTextEdit());
+ mw1.show();
+ QApplication::processEvents();
+ dw1->setFixedWidth(101);
+ QApplication::processEvents();
+
+ state = mw1.saveState();
+ }
+
+ //restore state
+ QMainWindow mw2;
+ QDockWidget *dw2 = new QDockWidget();
+ dw2->setObjectName("Left DockWidget");
+ mw2.addDockWidget(Qt::LeftDockWidgetArea, dw2);
+ mw2.setCentralWidget(new QTextEdit());
+ mw2.restoreState(state);
+ mw2.setStyleSheet("color:red");
+ mw2.show();
+ QApplication::processEvents();
+
+ QCOMPARE(dw2->width(), 101);
+}
+
//tests the restoration of the previous versions of window settings
void tst_QMainWindow::restoreStateFromPreviousVersion()
{