How can one hide the scrollbars in a QScrollArea
? Currently I use the hide()
method on the scrollbars returned by QScrollArea::horizontalScro
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 )
From Qt documents for scrollContentsBy()
:
Calling this function in order to scroll programmatically is an error, use the scroll bars instead (e.g. by calling QScrollBar::setValue() directly).
This piece of code can do the job:
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
verticalScrollBar()->hide();
verticalScrollBar()->resize(0, 0);