Important: Please read the Qt Code of Conduct -

QTreeView - Horizontal scroll bar is not working properly

  • Hi,

    I am facing difficulties with the horizontal scroll bar in Qtreeview.

    When I expand and the content exceeds the widget, I expect that scroll bar should appear.

        projectTreeView->header()->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    These are the properties I have set.

    What happens is that,
    After crossing 1000, I do get a scroll bar, but, it doesn't grow as when I keep expanding the tree.

    How do I get the better control?


  • Lifetime Qt Champion


    Out of curiosity, why do you need to modify your header ?

  • @SGaist I thought that's the way to get the control on sizing.

    If that is not correct, can you please recommend me the right way?


  • Lifetime Qt Champion

    AFAIK, by default the QTreeView will do what you want without any special handling. What model are you using ?

  • @SGaist Am using QStandardItemModel..

  • @kumararajas When I did a quick test, QTableView and QListView works good with respect to horizontal scroll bar.

    But, QTreeView is having some problems around. Not sure why.

    Can you please share any example or sample code where Horizontal scroll bar works good in QTreeView? I can use that as my reference and check what am I doing wrong.


  • This is still open.

    Any thoughts on this problem?

  • Lifetime Qt Champion

    Can you provide a minimal compilable sample application that triggers that ?

  • @SGaist Good question :)

    I have the implementation as part of my project. Let me see if I have strip of my code from the same and share it here. Else, I can also try a sample application which can reproduce this problem and share it here.

Log in to reply