1
votes

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 !

2
Maybe you need to add items for new column too?vahancho
i am adding text to new column using old TreeItems.DigviJay Patil
You need to show some code so people can understand what's wrong.user4516901
Try setting tv->header()->setStretchLastSection(false) on init and call tv->resizeColumnToContents(int col)each time you're adding a columnRobert
@Robert your solution works for me just add your solution in answer so that i can upvote you!DigviJay Patil

2 Answers

2
votes

Call

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

at the initialization and

treeWidget->resizeColumnToContent(column);

each time your adding a column.

0
votes

Looks like

resizeColumnToContents(int col)

will help you. (You should call it every time after adding new column)

Btw, don't forget to call

header()->setStretchLastSection(false)

on initialization of TreeView