Results 1 to 4 of 4

Thread: Doubt with spacing between widgets in layout managers

  1. #1
    Join Date
    Nov 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Doubt with spacing between widgets in layout managers

    Hi. I'm a newbie to Qt and I'm studying it using Python, but understanding C/C++ code is not a problem. My situation is this: I have a QHBoxLayout and I added a QGroupBox to it. Then I added some checkboxes to my QGroupBox (using a QVBoxLayout inside).

    My problem is: when the window is resized, the checkboxes grow apart (I believe they grow vertically) and I want them to stay together, as they do when the QGroupBox is in its minimum size.

    What should I do to achieve this?

  2. #2
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Doubt with spacing between widgets in layout managers

    You can add a spacer to the QVBoxLayout after the two checkboxes. The spacer takes up the excess space and pushes the checkboxes up, so they stay together. See http://doc.trolltech.com/4.4/qboxlayout.html#addStretch.

  3. #3
    Join Date
    Nov 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Doubt with spacing between widgets in layout managers

    Thank you, this solved my problem

    And what if I want to allocate any extra space to the other widget, instead of the groupbox? I added a QGLWidget next to the QGroupBox and I want any extra horizontal space to be given to the QGLWidget. How can I do it?

  4. #4
    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: Doubt with spacing between widgets in layout managers

    Set the sizePolicy property of the GL widget to expanding. In addition you can also set the group box's size policy to fixed.

Tags for this Thread

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.