How to hide scrollbar in QScrollArea?

前端 未结 4 785
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-11 04:26

How can one hide the scrollbars in a QScrollArea? Currently I use the hide() method on the scrollbars returned by QScrollArea::horizontalScro

相关标签:
4条回答
  • 2020-12-11 04:30

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

    0 讨论(0)
  • 2020-12-11 04:39

    Use this code:

    QAbstractScrollArea::setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff )
    QAbstractScrollArea::setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ) 
    
    0 讨论(0)
  • 2020-12-11 04:48

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

    0 讨论(0)
  • 2020-12-11 04:52

    This piece of code can do the job:

     setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     verticalScrollBar()->hide();
     verticalScrollBar()->resize(0, 0);
    
    0 讨论(0)
提交回复
热议问题