I have the following widget layout:
HBox
- VBox
- HBox
widget "A"
widget "B"
- widget "C"
- widget "D"
In other words, I have something like this:
+-----+--------------+
| A | |
+-----+ C |
| B | |
+-----+--------------+
| D |
+--------------------+
Depending on the content, “A” and “B” need to expand and consume as much vertical space as is necessary without showing any scrollbars. “D” can contract as necessary.
I tried setting the sizePolicy() of “A” and “B” to be “Minimum” and implemented a sizeHint() for “A” and “B” depending on what they are displaying. However, I still see scrollbars in “A” and “B” while “D” has more space than it needs.
I also tried “minimumExpanding” for the sizePolicy(), but I still keep seeing scrollbars.
How do I make sure that if space is available, “A” and “B” get preferential treatment so that scrollbars are avoided?
You can set the
minimumHeightandminimumWidthproperties of A and B to the lowest possible value where there are no scrollbars. They will still be able to expand but won’t shrink below that size.[Edit:]
After re-reading your question I realized your content of A and B don’t always have the same size. Obviously the approach above would only be possible if you know the size of the content whenever it changes. You can just call
setMinimumHeight()/setMinimumWidth()or equallysetMinimumSize()from your code in this case.