Reputation: 55
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?
Upvotes: 2
Views: 1256
Reputation: 12331
Use the Expanding
as size policy for A
and B
. For widget 'D' you should resize it every time the contents of A
and/or B
change. It's size policy should be minimum and you should use the setMinimumHeight
.
If a widget has scrollbars then it should inherit from the QAbstractScrollArea
. You could use the setHorizontalScrollBarPolicy
and the setVerticalScrollBarPolicy
in order to disable scrollbars:
A->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
B->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Upvotes: 2
Reputation: 12600
You can set the minimumHeight
and minimumWidth
properties 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 equally setMinimumSize()
from your code in this case.
Upvotes: 0