Retain width of vertical scrollbar when hidden in a QScrollArea
Unsolved
General and Desktop
-
Hi,
When using a QWidget inside a layout on a QScrollArea with horizontal scrollbar disabled and vertical scrollbar set to Qt::ScrollBarAsNeeded, it causes a resize of the width each time the vertical scrollbar is automatically activated/deactivated.
I can't find a way to keep the width of vertical scrollbar when it's hidden.
I've tried the following code:QSizePolicy size_policy = scrollarea_->verticalScrollBar()->sizePolicy(); size_policy.setRetainSizeWhenHidden(true); scrollarea_->verticalScrollBar()->setSizePolicy(size_policy);
Or is there an alternative solution using layout or spacer that can fill the gap of the of the scrollbar to avoid the resize of the width?
-
Try it out to set a fixed width with stylesheet of QScrollBar:vertical
https://doc.qt.io/qt-6/stylesheet-examples.html -
The width of the scrollbar is changed but it still doesn't retain the size when hidden.