From a6d7e09e89a73b3706aabbf2d08586f238348c7c Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 6 Jun 2014 13:53:58 +0200 Subject: [PATCH] QWidget: fix documentation for isEnabledTo(0) It is NOT always the same as isEnabled(). Added a unittest to prove it. Change-Id: I7717126835923e8c091249bfcdf81767c44fb5f7 Reviewed-by: Giuseppe D'Angelo --- src/widgets/kernel/qwidget.cpp | 8 +++++++- tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 65e435fbdc..7396808442 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -2912,7 +2912,13 @@ void QWidget::showNormal() This is the case if neither the widget itself nor every parent up to but excluding \a ancestor has been explicitly disabled. - isEnabledTo(0) is equivalent to isEnabled(). + isEnabledTo(0) returns false if this widget or any if its ancestors + was explicitly disabled. + + The word ancestor here means a parent widget within the same window. + + Therefore isEnabledTo(0) stops at this widget's window, unlike + isEnabled() which also takes parent windows into considerations. \sa setEnabled(), enabled */ diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 34936fa5b8..eac8ab2236 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -1210,6 +1210,12 @@ void tst_QWidget::isEnabledTo() QVERIFY( !childWidget->isEnabledTo( testWidget ) ); QVERIFY( grandChildWidget->isEnabledTo( childWidget ) ); QVERIFY( !grandChildWidget->isEnabledTo( testWidget ) ); + + QMainWindow* childDialog = new QMainWindow(testWidget); + testWidget->setEnabled(false); + QVERIFY(!childDialog->isEnabled()); + QVERIFY(childDialog->isEnabledTo(0)); + testWidget->setEnabled(true); } void tst_QWidget::visible()