How to hide scrollbar in QScrollArea?

How to hide scrollbars in QScrollArea ? I am currently using the hide() method on the scrollbars returned by QScrollArea::horizontalScrollBar() and QScrollArea::verticalScrollBar() , but the space reserved for the scrollbars still remains. Obviously, this looks very ugly and is not an efficient space. If I completely remove the scroll bars, I can no longer easily scroll them to a specific point using QScrollBar::setValue() .

+7
qt qscrollarea
source share
4 answers

Use this code:

 QAbstractScrollArea::setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ) QAbstractScrollArea::setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ) 
+15
source share

You can hide it using the stylesheet. Use height:0px; hide the horizontal scrollbar and width=0px; hide the vertical scroll bar. Like this:

 horizontalScrollBar()->setStyleSheet("QScrollBar {height:0px;}"); verticalScrollBar()->setStyleSheet("QScrollBar {width:0px;}"); 

And voila !. There are no scroll bars, and you can still control them with setValue() .

+15
source share

This piece of code can do the job:

  setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); verticalScrollBar()->hide(); verticalScrollBar()->resize(0, 0); 
+1
source share

From the Qt docs for scrollContentsBy() :

Calling this function to scroll programmatically is an error, use scrollbars instead (for example, by directly calling QScrollBar :: setValue ()).

+1
source share

All Articles