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()->setMinimumWidth(1000);
    
        projectTreeView->header()->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    
        projectTreeView->setTextElideMode(Qt::ElideNone);
        projectTreeView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        projectTreeView->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        projectTreeView->setSelectionBehavior(QAbstractItemView::SelectRows);
        projectTreeView->setSelectionMode(QAbstractItemView::SingleSelection);
        projectTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    

    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?

    Thanks,
    Kumara


  • Lifetime Qt Champion

    Hi,

    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?

    Thanks,
    Kumara


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

    Thanks,
    Kumara


Log in to reply
 

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