Results 1 to 14 of 14

Thread: Nested Layouts and sizePolicy

  1. #1
    Join Date
    Oct 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Nested Layouts and sizePolicy

    Hi,

    I'm trying to create a sort of indented list of checkboxes in the Designer. Here's how the result should look like:
    Form.png

    I'm using Horizontal Spacers to create actual indents, setting their sizeType to Fixed and sizeHint to whatever size I like. Then I group each spacer with its checkbox and enclose them in a QHBoxLayout. Then I apply a vertical layout to the whole widget. In the Designer it looks like this:
    FormInDesigner.png

    Now, when I resize the widget, the checkboxes are no longer spaced evenly in vertical direction:
    FormInDesignerResized.png

    My question: how can I control the vertical sizing behavior of nested QHBoxLayouts? There appears to be no such thing as a sizePolicy for the QHBoxLayout... I've tried several options of layoutSizeConstraint, but they don't seem to have any effect.

    Thanks!

  2. #2
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Nested Layouts and sizePolicy

    Put those two checkboxes into a single vertical layout... then try setting the layoutLeftMargin value

  3. #3
    Join Date
    Oct 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Nested Layouts and sizePolicy

    Thanks, but that doesn't really solve the problem with resizing:
    FormInDesignerResized2.png
    Still, the items in the nested layout behave differently compared to the others.

  4. #4
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Nested Layouts and sizePolicy

    you're right, I got the same result when I tried it.

    It seems such a simple problem. I'm sure there is a solution, hopefully one of the more experienced users can provide some insights.

  5. #5
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Nested Layouts and sizePolicy

    Try to mess around with the layoutStretch values for main layout.
    Results::
    nestedStre2.jpg nestedStre1.jpg
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  6. #6
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Nested Layouts and sizePolicy

    got it to work by adding horizontal spacers with sizeType 'Fixed'.

    layout.jpg

    result.PNG
    Last edited by schnitzel; 22nd October 2010 at 22:40. Reason: additional pic

  7. #7
    Join Date
    Oct 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Nested Layouts and sizePolicy

    Thanks, Talei! layoutStretch of 1,0,0,0,0,0... seems to work. Do you have a clue why would layoutStretch make a difference? I thought it only affects expandable widgets...

    Quote Originally Posted by schnitzel View Post
    got it to work by adding horizontal spacers with sizeType 'Fixed'.
    Schnitzel,

    What exactly have you done to make it work? My original spacers also had sizeType=Fixed.

    Quote Originally Posted by Talei View Post
    Try to mess around with the layoutStretch values for main layout.
    I have noticed that with layoutStretch, although nested layouts do not expand to infinity, the vertical spacing of checkboxes is still not EXACTLY the same: there is a little extra space around enclosed widgets:
    Form.png
    Last edited by pagapov; 23rd October 2010 at 03:04.

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

    Default Re: Nested Layouts and sizePolicy

    Is this what you wanted?

    If your style makes the indented boxes move to the right too much, change the horizontal size policy of the first indented box to MinimumExpanding.
    Attached Files Attached Files
    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.


  9. #9
    Join Date
    Oct 2010
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Nested Layouts and sizePolicy

    I would put them in their own vertical layout, then put a spacer on the left and add to a horizontal layout, and lastly add it all to one big vertical layout.

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

    Default Re: Nested Layouts and sizePolicy

    Actually probably the best method is to just use QTreeWidget and remove all the decorations from the viewport so that only items with checkboxes are rendered.
    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.


  11. #11
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Nested Layouts and sizePolicy

    @pagapov
    I assume that You want fluid / resizable layout that will arrange Your widgets vertically even, with the horizontal item indent.

    I don't know why Your Ui bahave that way. I tested with stretch and difference is only 2px. Here is my test Ui: aboutdlg.ui
    and PNGs (with "test markers")
    http://www.imagebam.com/image/8a479a103526056
    http://www.imagebam.com/image/6e962d103523909
    http://www.imagebam.com/image/aa3425103523910

    As for the clue, I don't have any , the only reason AFAIK for this to happens is that QVBoxLayout arrange items by their height and QHBoxLayout don't return correct height for the items inside it (from brief look at the src it actually return sizeHint so probably I'm wrong on this one). So it treats QHBoxLayout as expendable horizontally and thus the bigger size for this layout. But as I said, it's only untested theory, please correct my if I'm wrong, or simply see implementation of the Q[H/V]BoxLayout.
    I stumble upon similar behaviour with splitters and nested layouts so stretch fixed behaviour for me partially, there was still around 5-10px "free space" for particular splitter with layout.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  12. #12
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Nested Layouts and sizePolicy

    Quote Originally Posted by pagapov View Post
    Schnitzel,

    What exactly have you done to make it work? My original spacers also had sizeType=Fixed.
    I'm not sure, but here is the project.
    Maybe it was just a matter of getting rid of all intermediate files.
    Attached Files Attached Files

  13. #13
    Join Date
    Oct 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Nested Layouts and sizePolicy

    Quote Originally Posted by wysota View Post
    Actually probably the best method is to just use QTreeWidget and remove all the decorations from the viewport so that only items with checkboxes are rendered.
    Thanks for the suggestion (I already decided to go that way, actually)!
    But my question at this point is more theoretical than practical. I mean, I was wondering why the layout doesn't behave like I expected, and thought that there absolutely MUST be a good reason for this which I'm just unaware of. Because it's such a basic thing! At least, I'd like to know if this behavior is expected (and documented, hopefully) or it is a bug or some overlooked case.
    It all gets much worse when I try to compose a non-trivial grid layout...
    Hope to get more answers from experts


    Added after 6 minutes:


    Quote Originally Posted by Talei View Post
    I don't know why Your Ui bahave that way. I tested with stretch and difference is only 2px
    The actual difference depends on the style: 6 px in Plastique vs. 3 px in Windows Vista:
    Compare.png
    Not that much, but I don't want my UI be 2px precise
    Last edited by pagapov; 24th October 2010 at 03:27.

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

    Default Re: Nested Layouts and sizePolicy

    There are three things involved when calculating offsets between items - space distribution (according to size hint and size policies) margins and spacing. Now spacing has two subcases - a fixed spacing and a flexible spacing where the style decides that spacing between some two objects should be different than spacing between other two objects because the style guidelines say so (e.g. two radio buttons should have less spacing between them than a radio button and a line edit because probably those two buttons are somehow related to each other, etc.). Margins are quite simple - each layout either has some margin or not, if you put a layout in a layout you will notice that the contents of the internal layout are a bit off compared to the contents of the external layout - that's because of the margin. The last part - size hint and size policies (and also stretch and all the stuff related to it) are well documented so it should be easy to see where their influence is.

    So what you observe is the sum of the three components of space calculation, you have to decide which one (or two or maybe all three) is decisive in your situation.
    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. layouts, sizePolicy, sizeHint,
    By Kronen in forum Newbie
    Replies: 2
    Last Post: 5th November 2009, 17:43
  2. The use of SizePolicy
    By Placido Currò in forum Newbie
    Replies: 2
    Last Post: 9th April 2009, 22:10
  3. Nested Layout
    By starcontrol in forum Qt Programming
    Replies: 2
    Last Post: 9th April 2008, 12:47
  4. nested tables
    By Jeroen van der Waal in forum Qt Programming
    Replies: 1
    Last Post: 6th June 2007, 17:12
  5. Nested Plugins
    By Luis Rodriguez in forum Qt Programming
    Replies: 1
    Last Post: 10th March 2006, 22:00

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.