Important: Please read the Qt Code of Conduct -

Missing ScrollBar

  • I have created a QTreeListWidget that is part of my Layout. The width of the QTreeListWidget (or actually its encapsulating widget) is fixed to 200. I would expect a horizontal scrollbar to appear in case the text for any QTreeListWidgetItems is too long to be fully visible. However, I noticed that the width of the text is in fact not taken into account at all. The scrollbar only appears in case the selectors or icons come beyond the width of the QTreeListWidget. Any ideas how I can get a scrollbar in case the text does not fit anymore (as in the screenshot below)?

    Missing ScrollBar

  • Moderators

    check the horizontal scrollbar policy property of the tree widget. It should be either Qt::ScrollBarAsNeeded or Qt::ScrollBarAlwaysOn.

    If that's the case you can try:

    treeWidget->header()->setResizeMode( QHeaderView::ResizeToContents );

  • Thanks. I tried the following (where Explorer is my QTreeWidget) as there is no setResizeMode function (I am using Qt 5.12.0). Unfortunately, this alone did not give the desired effect.


    If I set the scrollbar policy to AlwaysOn, the scrollbar sows that there is nothing to scroll. So, I used setColumnCount to set the number of columns to 2 instead of the default of 1. Together with the above, that solved the problem. As I do not really understand the column part: should the number of columns be equal to the depth of the tree?

  • Lifetime Qt Champion

    The default elide mode for the views is 'ElideRight':

  • Interesting, I needed that for another part of my app. Thanks!
    However, without setting the number of columns to 2 it has however no effect...

  • Lifetime Qt Champion

    @ModelTech said in Missing ScrollBar:

    However, without setting the number of columns to 2 it has however no effect...

    The scrollbar is show, after you e.g. called resizeColumnToContents(). Just tested it in the designer

Log in to reply