Skip to content
Snippets Groups Projects
Commit 1748dc3e authored by Volker Hilsheimer's avatar Volker Hilsheimer
Browse files

QGroupBox: always disable children in a checkable, unchecked groupbox


The childEvent handler sets the enabled property of children as they are
added to the groupbox, but applications might later enable children and
check/uncheck the groupbox's checkbox in undefined order. In that case,
we would end up with enabled children inside a conceptually disabled
groupbox (the groupbox's checkbox represents the logical "disabled"
state), which breaks documented QWidget::enabled rules.

To make sure that all children are disabled as per the state of the
groupbox, we need to run that logic once the UI has been set up, and
before it becomes visible. This is what polishing is for, so listen
for that event in addition and handle it the same way as adding (which
duplicates things, but keeps existing code that might depend on things
being updated as they are added working).

Adds the case to the existing enabledChildPropagation test case.

[ChangeLog][QWidget][QGroupBox] Always disable children of a checkable,
unchecked group box before showing.

Change-Id: I978bd27b6f1a3f54ec745faeea529a98d0d93619
Fixes: QTBUG-25938
Reviewed-by: default avatarShawn Rutledge <shawn.rutledge@qt.io>
parent 81a79096
Branches
Tags
No related merge requests found
......@@ -389,9 +389,13 @@ bool QGroupBox::event(QEvent *e)
void QGroupBox::childEvent(QChildEvent *c)
{
Q_D(QGroupBox);
if (c->type() != QEvent::ChildAdded || !c->child()->isWidgetType())
/*
Children might have been enabled after being added to the group box, in which case
the childEvent handler ran too early, and we need to disabled children again.
*/
if (!(c->added() || c->polished()) || !c->child()->isWidgetType())
return;
QWidget *w = (QWidget*)c->child();
QWidget *w = static_cast<QWidget*>(c->child());
if (w->isWindow())
return;
if (d->checkable) {
......
......@@ -295,6 +295,12 @@ void tst_QGroupBox::enabledChildPropagation()
QVERIFY(!childWidget->isEnabled());
dialog = new QDialog(&testWidget);
QVERIFY(dialog->isEnabled());
// children that are enabled after adding should still be disabled before
// they are shown
childWidget->setEnabled(true);
testWidget.show();
QVERIFY(!childWidget->isEnabled());
}
void tst_QGroupBox::sizeHint()
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment