[PyQt] findChildren: setting visibility problems
Florian Bruhin
me at the-compiler.org
Mon Oct 13 20:25:30 BST 2014
* Chris Wood <c.c.wood at gmail.com> [2014-10-13 20:12:05 +0100]:
> I've found that where I have a QLabel as a child of my QWidget, and a
> QLabel which is a child of a QGroupBox which is a child of my QWidget, and
> I toggle the visibility of all the children of the QWidget via the click
> action of a button:
>
> def toggleVis(self):
> self.results = findChildren((QLabel,QGroupBox))
> print self.results
> for w in self.results:
> w.setVisible(not w.isVisible())
>
> After hiding the objects initially, and clicking the button again, the
> QLabel which is a child of the QGroupBox does not reappear, but all 3
> objects are listed when self.results is printed (full code at end of
> email). I expected this to work, since findChildren is recursive.
> However, it *does* work if I reverse the list (for w in
> reverse(self.results)). I get the same behaviour on both Unix (Fedora 20)
> and Windows 7. Is this documented? Perhaps a different way round this would
> be to specify names (I could probably use some regex to ensure I capture
> the objects I want), but wanted to make sure I hadn't missed something
> obvious from the docs first...
Hmm, shouldn't calling setVisible(True) (or show) on a widget already
also show it's child widgets anways (if they never were explicitely
hidden)?
From the docs to setVisible:
Calling setVisible(true) or show() sets the widget to visible
status if all its parent widgets up to the window are visible. If
an ancestor is not visible, the widget won't become visible until
all its ancestors are shown.
An explicitly hidden widget will never become visible, even if all
its ancestors become visible, unless you show it.
It sounds to me like something like this happens:
- The first item is a child of the "root"
- You show it
- The children get shown as well
- You get to the children and because of your
"setVisible(not w.isVisible()" you hide it again.
Florian
--
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
GPG 0xFD55A072 | http://the-compiler.org/pubkey.asc
I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20141013/cceb5541/attachment.sig>
More information about the PyQt
mailing list