Search code examples
c++qtqt4qt-designer

Qt get children from layout


I try to hide all widgets in layout. But looks like findChildren doesn't work for layout.

Here's my sample code:

QLayout * layout = widget -> findChild<QLayout *> (layoutName);
QList<QWidget *> list = layout -> findChildren<QWidget *> ();

cout << list.size() << endl;

size is 0, but inside this layout I have a few widgets. But the same code works fine if I try to get widgets from parent widget.

How I can get them from appropriate layout?


Solution

  • The layout does not "inject" itself in the parent-child tree, so the widgets stay (direct) children of their parent widget.

    You could use QLayout::count() and QLayout::itemAt() instead.