Unsolved Minimum widget size to cover QScrollArea viewport?
-
What is the best way to get the width and height of the visible portion of a QScrollArea viewport? I need to manually set the height of the widget because the height always matches the viewport size but the width might be bigger depending on the level of custom zoom (it's a timeline widget). It would also be ideal to get this prior to showing the scroll area, or at least after QScrollArea::show() is called but before it is animated horizontally on screen.
I found the following inaccurate in all cases:
scrollArea->viewport()->size()
scrollArea->viewportSizeHint()
scrollArea->viewport()->visibleRegion().boundingRect().size()Thanks!
-
@patrickkidd said in Minimum widget size to cover QScrollArea viewport?:
I need to manually set the height of the widget because the height always matches the viewport
Then it's probably easier to just set
scrollArea->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
-
@VRonin That should adjust the viewport to my widget size, correct? But I need to adjust my widget size to the visible rect of the scroll area. Or am I misunderstanding this?
-
Hi,
Out of curiosity, what kind of widget are you putting in that QScrollArea ?
-
@SGaist It is a custom timeline widget which shows events chronologically going from left to right, and zooms by simply expanding the width of the widget on vertical wheel events. The vertical scale of the widget always remains the same. Events are laid out to scale horizontally so you get a sense of relative time between them.
So the height of the widget needs to always be the height of the scroll area viewport so it never scrolls vertically, and the widget needs to always be at minimum the width of the viewport, or a positive multiple of the width of the viewport as determined by the level of zoom.
-
Wouldn't a model and a custom view be simpler to handle that kind situation ?