Results 1 to 2 of 2

Thread: layout->children() of size 0, even after layout->addWidget

  1. #1
    Join Date
    Jul 2015
    Posts
    52
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default layout->children() of size 0, even after layout->addWidget

    Does layout->children() not include QWidgets added with addWidget?

    Qt Code:
    1. QWidget* wid = new QWidget();
    2. formLayout->addWidget(wid);
    3. QList<QObject*> blah = formLayout->children();
    4. qDebug() << blah << " - blah - " << blah.size();
    To copy to clipboard, switch view to plain text mode 

    Size is 0 and blah is empty.

    However, its parent childern does include the added widget. So ->addWidget() doesn't set the layout as parent but the layout's parent? Are layouts then assumed to never be parents?

    How can I add QWidgets to a layout so that I can use findChild by its name?

    Cheers

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: layout->children() of size 0, even after layout->addWidget

    Quote Originally Posted by quimnuss View Post
    Does layout->children() not include QWidgets added with addWidget?
    No.

    The parent of a widget is either 0 or another widget.
    So QLayout is never a parent of a widget, so widget's never appear in a layout's children() list.

    Quote Originally Posted by quimnuss View Post
    How can I add QWidgets to a layout so that I can use findChild by its name?
    The layout is just arranging widgets on behalf of a parent widget, which you can use as a starting point for findChild().

    Chers,
    _

Similar Threads

  1. size of horizontal layout
    By maarvi in forum Newbie
    Replies: 5
    Last Post: 28th June 2011, 10:24
  2. Replies: 0
    Last Post: 12th December 2010, 05:09
  3. Replies: 0
    Last Post: 26th October 2010, 17:59
  4. Replies: 0
    Last Post: 25th May 2009, 10:00
  5. How do I get the children of a layout?
    By ksierens in forum Qt Programming
    Replies: 1
    Last Post: 25th January 2008, 14:57

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.