PDA

View Full Version : Using setEnabled(false) on parent widgets disables all children



blivrail
26th May 2008, 23:08
Hello,

On the Qt 4.4 documentation (http://doc.trolltech.com/4.4/qwidget.html#enabled-prop), it states that if you set a parent widget (such as a QMainWindow) to disabled using setEnabled( false ), all children widgets are implicitly disabled.

Using this call, is there a way to keep one children widget enabled?

I know I can do something like this:



QList<QWidget*> list = parentWidget->findChildren<QWidget*>() ;
foreach( QWidget* w, list )
{
w->setEnabled( false ) ;
}
childWidget->setEnabled( true ) ;


But then I lose the existing enabled/disabled state of the widgets.

Thanks!

vycke
27th May 2008, 14:45
You could always put the other child widgets into group boxes & disable the group, that would keep the enable/disable status of the widget.

Vycke

blivrail
28th May 2008, 17:51
Thanks Vycke.

I ended up using the method I described in my first post, because moving widgets around would have been a little messy ;)

vycke
29th May 2008, 13:50
If you want to keep the previous enabled/disabled status, you could always keep the value in a dynamic property (QObject::setProperty(const char* name, const QVariant& value) -- retrieved with QObject::property(const char* name)).

It's nice to be able to use some parts of QT/QObject in ways that you need -- such as the dynamic properties & objectName :)

Vycke