QScrollBar and handle height

  • I can not set handle height. My css:
    QScrollBar:vertical {
    border-image: url(:/images/scroll_bg.png);
    width: 20px;
    margin: 5px 5px 52px 0px;

    QScrollBar::handle:vertical {
    background: url(:/images/handle.png);
    height: 5px;
    width: 5px;
    /border-radius: 3px;/

    QScrollBar::add-page:vertical {
    border-image: url(:/images/scroll_add_page.png);

    QScrollBar::sub-page:vertical {
    margin: 5px 2px 0px 2px;
    border-image: url(:/images/scroll_sub_page.png);

    QScrollBar::add-line:vertical {
    border-image: url(:/images/add_line.png);
    height: 26px;
    margin: 0px 5px 5px 0px;
    subcontrol-origin: margin;

    QScrollBar::sub-line:verticall {
    border-image: url(:/images/sub_line.png);
    height: 26px;
    margin: 0px 5px 26px 0px;
    subcontrol-position: bottom;
    subcontrol-origin: margin;

    QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
    background: none;

  • mmm...
    How can I get handle from scrollbar to set him fixed size

  • Moderators

    The main idea of the handle height is that it's height represents a percentage of the total height it is scrolling on.

    Eg if the actual size is twice the scroll area then the handle height would be half the visible area.

    Why would you want to change this behaviour? What is your specific use case?

  • I agree with Eddy, changing the default behavior of a scroll bar can confuse the user. However I would try to change values into the "QStyleOptionSlider":http://doc.qt.nokia.com/latest/qstyleoptionslider.html#details to see if this trick works for drawing the scroll bar. It is just an idea.

  • thnx but i dont know how :(

    @void TreeWidget::paintEvent(QPaintEvent *event)
    QPainter painter(this);
    QStyleOptionSlider option;

    style()->drawComplexControl(QStyle::CC_Slider, &option, &painter, this);


  • Moderators

    Just a thought: why not use a "QSlider":http://doc.qt.nokia.com/4.8-snapshot/qslider.html#details?

    Sounds this is what you want and you can use stylesheet to change the look of the handle.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.