QScrollArea stops limiting parent QDialog size
-
I am using
Qt5
withPySide2
I am experiencing some behavior that is different from what I would expect. Would anyone be able to clarify if I am misunderstanding something?
As soon as I add a
QScrollArea
to aQDialog
, I lose the ability to constrain the dialog's maximum size by the scrollbar contents' minimum size. This is expected behavior from aQScrollArea
I think, but it persists when I switch the scrollbars off, which is not what I would expect.My setup is fairly simple:
- In Designer, create a new
QDialog
- Add a
QListWidget
- Set the dialog's layout to vertical
- Set the list widget's minimum width to 600
Run the code. I can now resize the dialog, but I can't make it smaller than the list widget's size allows. This is what I expected.
Now add some changes:
- Place a
QScrollArea
on theQDialog
- Move the list widget to the scroll area
- Set the scroll area's layout to vertical
Run the code again. The dialog can now be resized to be smaller than the list widget's size allows and a scrollbar appears when I do. This is also what I expected.
One final change:
- Set the scroll area's horizontal scroll bar policy to
ScrollBarAlwaysOff
Run the code.
- Behavior: The same as with the scrollbar enabled (I can make the dialog smaller than the list widget allows). The only difference is that the scrollbar is not shown.
- Expected: The switched-off scroll bar enforces the dialog's maximum size to obey the list widget's minimum width as it would in the first example.
So what I am looking for is a
QScrollArea
that behaves exactly like aQScrollArea
in vertical direction, but that behaves exactly as if it did not exist in horizontal direction.I am trying to avoid doing any manual calculations on the window size if possible.
Is this a limitation in Qt or did I miss a setting that would allow getting this behavior?
- In Designer, create a new
-
-
Hi,
If you want to achieve that you have to set the constraint yourself on the QScrollArea width when you hide the scrollbar.
-
@SGaist Thanks for your input.
Can you clarify what you mean with "set the constraint"? Do you mean I need to limit the
QScrollArea
's width at some magic number? Because that's what I wanted to avoid.I was looking for a solution that allows auto-formatting, but not the way a
QScrollArea
does but rather the way aQWidget
does it, so I get theQScrollArea
behaviour in one direction and theQWidget
behaviour in the other direction.And maybe clarification: Is this behaviour by design? I would kind of expect that a disabled scroll bar would not replicate the resizing behaviour as if a scroll bar was present, or is there a use case I am missing?