How can one hide the scrollbars in a QScrollArea
? Currently I use the hide()
method on the scrollbars returned by QScrollArea::horizontalScrollBar()
and QScrollArea::verticalScrollBar()
but the space reserved for scrollbars still remains. Obviously this looks very ugly and is not space efficient. If I remove the scrollbars altogether I can no longer easily scroll to a specific point using QScrollBar::setValue()
.
To turn off the default scroll bar go in Settings → Preferences → Advanced → Browsing, deactivate “Show scrollbars”. Save this answer. Show activity on this post.
You can hide it using a style sheet.
Use height:0px;
to hide the horizontal scroll bar and width=0px;
to hide the vertical scroll bar.
Like that:
horizontalScrollBar()->setStyleSheet("QScrollBar {height:0px;}");
verticalScrollBar()->setStyleSheet("QScrollBar {width:0px;}");
And voila!.No scroll bars, and you can still manipulate them using setValue()
.
Use this code:
QAbstractScrollArea::setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff )
QAbstractScrollArea::setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With