Results 1 to 3 of 3

Thread: Layout in Qt Designer

  1. #1
    Join Date
    Nov 2010
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Layout in Qt Designer

    Hello guys!

    I am a total Qt beginner and I am still struggling a little bit with layouts. My 2 questions:

    1) When I create a layout per code I make it like this:
    Qt Code:
    1. QHBoxLayout *mainLayout = new QHBoxLayout;
    2. mainLayout->addLayout(leftLayout);
    3. mainLayout->addLayout(rightLayout);
    4. setLayout(mainLayout);
    To copy to clipboard, switch view to plain text mode 
    I explicitly set the layout of this widget by calling setLayout(). But when I create my Window in the Qt Designer, there isn't a call to setLayout() at all! The only thing I noticed was this:
    Qt Code:
    1. verticalLayout = new QVBoxLayout(centralwidget);
    2. verticalLayout = new QVBoxLayout(centralwidget);
    To copy to clipboard, switch view to plain text mode 
    Does this line mean the centralwidget now has a vertical layout? Or is this just used for resource management (so that the layout is deleted when the centralwidget is deleted)?

    2) Lets take the example from question 1: 3 buttons in a horizontal layout. I don't understand why each button has a Horizontal and Vertical Stretch AND the layout itself also has a layoutStretch (0,0,0). How are they related? Does the layoutStretch values of the QHBoxLayout override the horizontal strech values of the contained widgets?

    Thanks!

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Layout in Qt Designer

    Quote Originally Posted by eiswand View Post
    Does this line mean the centralwidget now has a vertical layout? Or is this just used for resource management (so that the layout is deleted when the centralwidget is deleted)?
    Both. If I remember correctly the setLayout() way of doing things ensures the layout is resized with the widget. The other doesn't or didn't. I always use the setLayout method as well.

    ) Lets take the example from question 1: 3 buttons in a horizontal layout. I don't understand why each button has a Horizontal and Vertical Stretch AND the layout itself also has a layoutStretch (0,0,0). How are they related? Does the layoutStretch values of the QHBoxLayout override the horizontal strech values of the contained widgets?
    The stretch factors on widgets tell the containing layout how to handle the resizing. You can also tell the layout to set a certain stretch factor on a widget. However, I think that the layoutStretch (which I cannot find by that name in the documentation) would be the stretch factor of the layout itself. That would make sense to me since the layouts can be embedded in other layouts.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Layout in Qt Designer

    I never use setLayout() and my layouts and widget sizes are always fine.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. layout and designer
    By franco.amato in forum Qt Tools
    Replies: 1
    Last Post: 23rd September 2010, 05:46
  2. Designer Layout Tips?
    By GimpMaster in forum Newbie
    Replies: 3
    Last Post: 3rd June 2009, 21:17
  3. how to promote layout in Designer?
    By homerli in forum Qt Tools
    Replies: 1
    Last Post: 11th May 2009, 16:40
  4. How can I set a layout to a dock inside Qt Designer?
    By ricardo in forum Qt Programming
    Replies: 4
    Last Post: 1st May 2009, 10:17
  5. Can I insert expanding layout in Qt Designer?
    By zolookas in forum Newbie
    Replies: 2
    Last Post: 6th October 2008, 18:17

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.