3 Attachment(s)
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:
Attachment 5364
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:
Attachment 5365
Now, when I resize the widget, the checkboxes are no longer spaced evenly in vertical direction:
Attachment 5366
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!
Re: Nested Layouts and sizePolicy
Put those two checkboxes into a single vertical layout... then try setting the layoutLeftMargin value
1 Attachment(s)
Re: Nested Layouts and sizePolicy
Thanks, but that doesn't really solve the problem with resizing:
Attachment 5367
Still, the items in the nested layout behave differently compared to the others.
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.
2 Attachment(s)
Re: Nested Layouts and sizePolicy
Try to mess around with the layoutStretch values for main layout.
Results::
Attachment 5379 Attachment 5380
2 Attachment(s)
Re: Nested Layouts and sizePolicy
got it to work by adding horizontal spacers with sizeType 'Fixed'.
Attachment 5381
Attachment 5382
1 Attachment(s)
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
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
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:
Attachment 5384
1 Attachment(s)
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.
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.
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.
1 Attachment(s)
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: Attachment 5391
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.
1 Attachment(s)
Re: Nested Layouts and sizePolicy
Quote:
Originally Posted by
pagapov
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.
1 Attachment(s)
Re: Nested Layouts and sizePolicy
Quote:
Originally Posted by
wysota
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
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:
Attachment 5394
Not that much, but I don't want my UI be 2px precise :(
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.