diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-12-29 11:44:04 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-12-29 12:12:44 (GMT) |
commit | 03baad51d584778a99f4b393232ccc1312db3391 (patch) | |
tree | 9ff318a63edd31614442afc1710ac93ca0826009 | |
parent | 4bd7e6930fcd9e04696aa5426691cd90ba383a32 (diff) | |
download | Qt-03baad51d584778a99f4b393232ccc1312db3391.zip Qt-03baad51d584778a99f4b393232ccc1312db3391.tar.gz Qt-03baad51d584778a99f4b393232ccc1312db3391.tar.bz2 |
Fixes crash when widget with WA_StaticContents child become toplevel.
Happens for example if a DockWidget is undocked and has a child
whith the WA_StaticContents attribute.
The parent does not change (so newParent is false) but still, the
top level widget change. So staticWidget need to be moved to the
new backingstore.
Reviewed-by: Benjamin Poulain
Task-number: QTBUG-6883
-rw-r--r-- | src/gui/kernel/qwidget.cpp | 11 | ||||
-rw-r--r-- | tests/auto/qwidget/tst_qwidget.cpp | 30 |
2 files changed, 34 insertions, 7 deletions
diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index e551a1d..81f38ec 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -9774,13 +9774,12 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f) } #endif - if (newParent) { - if (QWidgetBackingStore *oldBs = oldtlw->d_func()->maybeBackingStore()) { + if (QWidgetBackingStore *oldBs = oldtlw->d_func()->maybeBackingStore()) { + if (newParent) oldBs->removeDirtyWidget(this); - // Move the widget and all its static children from - // the old backing store to the new one. - oldBs->moveStaticWidgets(this); - } + // Move the widget and all its static children from + // the old backing store to the new one. + oldBs->moveStaticWidgets(this); } if ((QApplicationPrivate::app_compile_version < 0x040200 diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index 3e14b56..2d04cc5 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -66,6 +66,8 @@ #include <private/qapplication_p.h> #include <qcalendarwidget.h> #include <qmainwindow.h> +#include <qdockwidget.h> +#include <qtoolbar.h> #include <QtGui/qpaintengine.h> #include <private/qbackingstore_p.h> @@ -356,6 +358,7 @@ private slots: void paintOnScreenPossible(); #endif void reparentStaticWidget(); + void QTBUG6883_reparentStaticWidget2(); #ifdef Q_WS_QWS void updateOutsideSurfaceClip(); #endif @@ -8728,6 +8731,31 @@ void tst_QWidget::reparentStaticWidget() // Please don't crash. paintOnScreen.resize(paintOnScreen.size() + QSize(2, 2)); QTest::qWait(20); + +} + +void tst_QWidget::QTBUG6883_reparentStaticWidget2() +{ + QMainWindow mw; + QDockWidget *one = new QDockWidget("one", &mw); + mw.addDockWidget(Qt::LeftDockWidgetArea, one , Qt::Vertical); + + QWidget *child = new QWidget(); + child->setPalette(Qt::red); + child->setAutoFillBackground(true); + child->setAttribute(Qt::WA_StaticContents); + child->resize(100, 100); + one->setWidget(child); + + QToolBar *mainTools = mw.addToolBar("Main Tools"); + mainTools->addWidget(new QLineEdit); + + mw.show(); + QTest::qWaitForWindowShown(&mw); + + one->setFloating(true); + QTest::qWait(20); + //do not crash } #ifdef Q_WS_QWS @@ -9726,7 +9754,7 @@ public: void deleteBackingStore() { if (static_cast<QWidgetPrivate*>(d_ptr.data())->maybeBackingStore()) { - delete static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->backingStore; + delete static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->backingStore; static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->backingStore = 0; } } |