diff options
author | Mitch Curtis <mitch.curtis@digia.com> | 2012-11-09 10:53:22 (GMT) |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-11-28 12:29:35 (GMT) |
commit | d8cbb158b7013fdf889657f6197eab1b972949be (patch) | |
tree | 0a7fe5df566d127297e1dfc912b41bec400472ae /tests | |
parent | d1dfc461276ba53d870289b00a97d08df005e0b3 (diff) | |
download | Qt-d8cbb158b7013fdf889657f6197eab1b972949be.zip Qt-d8cbb158b7013fdf889657f6197eab1b972949be.tar.gz Qt-d8cbb158b7013fdf889657f6197eab1b972949be.tar.bz2 |
Fix conflict between QMainWindow::restoreState, QWidget::setStylesheet.
If QMainWindow::restoreState() then QWidget::setStylesheet() were
called before the QMainWindow is shown, the size of QDockWidget can not
be restored.
QWidget::setStylesheet() will generate QEvent::StyleChange event, which
will cause the function QDockAreaLayout::fitLayout() to be called
before the layout of MainWindow is activated. Although the state info
has been stored in a QMainWindowLayoutState variable by
QMainWindow::restoreState(), but QMainWindowLayout::setGeometry() still
isn't called at present. So QDockAreaLayout::fitLayout() will force the
size of dockwidgets and centralwidget to be calculated using the wrong
geometry, which will break the state restored by
QMainWindow::restoreState().
This is a side effect of 692e9103ebb85b90e79377206d5d03b704d43d42.
This patch is a backport of d2f65aa470fe30849a01380e4a50e8a4ebbce07e.
Task-number: QTBUG-15080
Change-Id: I5b912e80e99b1f8b7a6f2a9a3e541fac3455c3db
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
Reviewed-by: Debao Zhang <hello@debao.me>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qmainwindow/tst_qmainwindow.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
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() { |