[PyQt] findChildren: setting visibility problems

Chris Wood c.c.wood at gmail.com
Tue Oct 14 16:01:35 BST 2014


Ah, thanks - that explanation seems to make sense with what's happening.
I'm not sure the solution I've got (calling reversed() on the list) is the
*most* robust, but it works (at least for now!).

Cheers,
Chris

On 13 October 2014 20:25, Florian Bruhin <me at the-compiler.org> wrote:

> * 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/
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20141014/2122c8eb/attachment.html>


More information about the PyQt mailing list