Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

qtreeview vertical scrollbar



  • hello i have treeview

    I want to put the scroll bar on the right.

    MyStyleSheet is this
    QTreeView{border : none; background-color : %4; outline :0; padding-left : 24px; padding-right : 24px;}

    If i give the view an padding Scroll bar follows

    How can I make the scroll bar close to the right?


  • Lifetime Qt Champion

    Hi,

    On the right of what ?
    QTreeView's scroll bars are by default on the right for the vertical one and on the bottom for the horizontal one.


  • Lifetime Qt Champion

    Hi
    Just remove the right padding. Since it the thing that gives the gap anyway.

    alt text

    The scrollbar is next to the internal viewport so padding the QTreeWidget itself will produce a empty space.



  • @SGaist @mrjj
    thank you for your answer

    I adjusted the size of the Treeview item, but when I give the padding to the TreeView, a scroll bar follows.

    I want it to look like the following picture (Currently the scroll bar is attached to the side of the item )
    1554356b-2a83-4a47-a1f7-1e2e31c4b1fd-image.png


  • Lifetime Qt Champion

    Hi
    The QTreeView is a QAbstractScrollArea which actually handles the items with its viewport()
    so you cant change it via QTreeView in stylesheet
    as its not the one that draws the items, nor the one that has the scrollbars.

    From a fast test with

    QAbstractScrollArea {
    border : none; background-color : red; outline :0; padding-left : 24px; padding-right : 0px;
    }
    

    and in code
    ui->treeView->viewport()->setStyleSheet("padding-right : 24px;" );

    I get this which you might be able to tweak to get the exact look. ( at least i hope so :)

    alt text

    Do note that the header view (name, size etc) don't care about the margin.
    I did not look into this but I'm sure its also fixable if needed.



  • @mrjj

    Thank you for answer. Could you send me some code you tested? If the style sheet is applied incorrectly, it cannot be applied.


  • Lifetime Qt Champion

    @Qt-Jo-Ha

    Hi
    I just placed a treeview on a form, right click and "Change Style sheet"
    then use the

    QAbstractScrollArea {
    border : none; background-color : red; outline :0; padding-left : 24px; padding-right : 0px;
    }
    

    and then i constructor for mainwindow i did

    ui->treeView->viewport()->setStyleSheet("padding-right : 24px;" );

    and also used a file model to have some data.



  • @mrjj

    thank you i try it!!


Log in to reply