Results 1 to 4 of 4

Thread: Using setEnabled(false) on parent widgets disables all children

  1. #1
    Join Date
    Apr 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Using setEnabled(false) on parent widgets disables all children

    Hello,

    On the Qt 4.4 documentation, 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:

    Qt Code:
    1. QList<QWidget*> list = parentWidget->findChildren<QWidget*>() ;
    2. foreach( QWidget* w, list )
    3. {
    4. w->setEnabled( false ) ;
    5. }
    6. childWidget->setEnabled( true ) ;
    To copy to clipboard, switch view to plain text mode 

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

    Thanks!

  2. #2
    Join Date
    Dec 2007
    Location
    Austin, TX
    Posts
    43
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using setEnabled(false) on parent widgets disables all children

    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

  3. #3
    Join Date
    Apr 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using setEnabled(false) on parent widgets disables all children

    Thanks Vycke.

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

  4. #4
    Join Date
    Dec 2007
    Location
    Austin, TX
    Posts
    43
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using setEnabled(false) on parent widgets disables all children

    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:roperty(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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.