Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide scrollbar in QScrollArea?

Tags:

qt

qscrollarea

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().

like image 654
pafcu Avatar asked Aug 01 '10 18:08

pafcu


People also ask

How do I get rid of the scroll bar on opera GX?

To turn off the default scroll bar go in Settings → Preferences → Advanced → Browsing, deactivate “Show scrollbars”. Save this answer. Show activity on this post.


2 Answers

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().

like image 136
MadeOfAir Avatar answered Oct 02 '22 17:10

MadeOfAir


Use this code:

QAbstractScrollArea::setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff )
QAbstractScrollArea::setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ) 
like image 39
Mason Zhang Avatar answered Oct 02 '22 15:10

Mason Zhang