Results 1 to 2 of 2

Thread: A question about adding to layout

  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default A question about adding to layout

    I want to add childWidgets to a layouted parentWidget at runtime. I need to construct the children like

    Qt Code:
    1. ChildWidget* child = new ChildWidget(parentWidget);
    To copy to clipboard, switch view to plain text mode 

    right? So now I would expect the child to be layed out according to the parentWidget's layout, but it doesn't happen. It seems like I explicitely have to:

    Qt Code:
    1. ChildWidget* child = new ChildWidget(parentWidget);
    2. parentWidget->layout()->addWidget(child);
    To copy to clipboard, switch view to plain text mode 

    Is this the right way? It feels like I'm adding the child to the parent twice.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: A question about adding to layout

    Quote Originally Posted by Cruz View Post
    Is this the right way? It feels like I'm adding the child to the parent twice.
    you do right. if a child has no parent then QLayout::addWidget set parent, in another if a child has a parent, has been layouted and that parent not equal to the layout's parent then QLayout::addWidget you'll an error on console.
    qWarning("QLayout::addChildWidget: %s \"%s\" in wrong parent; moved to correct parent",
    w->metaObject()->className()
    Last edited by spirit; 20th January 2009 at 12:52.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Qt like Layout Manager available for .NET platform
    By vkhaitan in forum Qt Programming
    Replies: 0
    Last Post: 5th November 2008, 13:36
  2. Replies: 3
    Last Post: 4th April 2008, 19:51
  3. Adding qpaint object to a Layout
    By Rooster in forum Newbie
    Replies: 6
    Last Post: 13th February 2008, 13:12
  4. Qt layout memory issue
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 25th August 2007, 17:11
  5. simple thread layout question
    By mhoover in forum Qt Programming
    Replies: 1
    Last Post: 12th August 2006, 11:02

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.