Search code examples
c++qtqtreewidget

How to repaint QTreeWidget?


I have QTreeWidget. In which I'm adding new column dynamically on button click event using setHeaderLabels. This API add new column in TreeWidget but column is not visible in current TreeWidget area. It adds a scroll bar in TreeWidget. Therefore to view newly added column user has to scroll the tree. This my scenario but I don't want to scroll. I have used update() function even though its not showing new column. Is there any way to repaint the widget. Thank you !


Solution

  • Call

    treeWidget->header()->setStretchLastSection(false);
    

    at the initialization and

    treeWidget->resizeColumnToContent(column);
    

    each time your adding a column.