From 18bb58a5a6f6669d6e55cc1e58b45a3437610185 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 29 Jul 2014 23:51:45 +0200 Subject: [PATCH] QProgressDialog: fix setBar() not properly adopting the new QProgressBar The "adoption" code is taken from setLabel(). Task-number: QTBUG-40503 Change-Id: Id512b28eb756b4a80e5701e599e2cbdf5346ff62 Reviewed-by: David Faure --- src/widgets/dialogs/qprogressdialog.cpp | 8 ++++++++ .../dialogs/qprogressdialog/tst_qprogressdialog.cpp | 7 ------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/widgets/dialogs/qprogressdialog.cpp b/src/widgets/dialogs/qprogressdialog.cpp index 35a75adea2a..bcfdb03f2f8 100644 --- a/src/widgets/dialogs/qprogressdialog.cpp +++ b/src/widgets/dialogs/qprogressdialog.cpp @@ -505,9 +505,17 @@ void QProgressDialog::setBar(QProgressBar *bar) } delete d->bar; d->bar = bar; + if (bar) { + if (bar->parentWidget() == this) + bar->hide(); // until we resize + else + bar->setParent(this, 0); + } int w = qMax(isVisible() ? width() : 0, sizeHint().width()); int h = qMax(isVisible() ? height() : 0, sizeHint().height()); resize(w, h); + if (bar) + bar->show(); } diff --git a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp index 86b9d7eee29..4e54c445b80 100644 --- a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp +++ b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp @@ -218,7 +218,6 @@ void tst_QProgressDialog::settingCustomWidgets() QVERIFY(!dlg.isAncestorOf(bar)); dlg.setBar(bar); - QEXPECT_FAIL("", "QProgressBar doesn't adopt custom progress bar as children", Continue); QVERIFY(dlg.isAncestorOf(bar)); QTest::ignoreMessage(QtWarningMsg, "QProgressDialog::setBar: Attempt to set the same progress bar again"); dlg.setBar(bar); // setting the same widget again should not crash @@ -227,13 +226,7 @@ void tst_QProgressDialog::settingCustomWidgets() QVERIFY(!l); QVERIFY(!btn); -#if 0 - QEXPECT_FAIL("", "QProgressBar doesn't clean up custom progress bars", Continue); QVERIFY(!bar); -#else - // make cleanup() pass - delete bar; -#endif } class QTestTranslator : public QTranslator