Solved How can I permanently show scrollbars?
-
I want a set of scroll bars to be a permanent part of the UI. I want them to always be visible. The following snippet is not enough.
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
I want the scroll bars to be visible even when they aren't necessary. How can I achieve this?
-
@Kerndog73 Are you sure this scrollArea is the correct one? It looks like it is allocated on the stack. Where do you execute this code and can you show it?
-
@jsulm My actual code is slightly different. I'm deriving from
QScrollArea
. I'm also using customQScrollBar
s. This is more similar to what I'm doing:class ScrollBar final : public QScrollBar { public: ScrollBar(Qt::Orientation orient, QWidget *parent) : QScrollBar{orient, parent} {} }; class ScrollArea final : public QScrollArea { public: explicit ScrollArea(QWidget *parent) : QScrollArea{parent} { setVerticalScrollBar(new ScrollBar{Qt::Vertical, this}); setHorizontalScrollBar(new ScrollBar{Qt::Horizontal, this}); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); } };
Is
Qt::ScrollBarAlwaysOn
supposed to make the scrollbar always visible or am I experiencing expected behaviour? -
@Kerndog73 From documentation (https://doc.qt.io/qt-5/qt.html#ScrollBarPolicy-enum):
"QAbstractScrollArea always shows a scroll bar. This property is ignored on systems with transient scroll bars (e.g., on Mac from version 10.7)."On which platform are you?
-
@jsulm I'm on a mac. Is there any way around this? Will I have to make my own scroll area from scratch if I want this behaviour? Maybe the scroll area could emulate scroll bars by setting content margins, responding to mouse events and painting? There must be a better way!
BTW, how do I earn reputation on this site? Having to wait 10 minutes to reply is kind of annoying.
-
@Kerndog73 Maybe you could use https://doc.qt.io/Qt-5/qscrollbar.html instead of the scroll area, but this means more work. Also, do you really want to work against platform UI design guidelines?
-
Hi,
I agree with @jsulm. What is your goal behind showing these scrollbars permanently on macOS ? It's been 7 versions since they are transient and everybody will expect that. Showing them permanently will make your application feel broken to your users.
-