How can I make a QTreeView to auto-adjust the wigth of the columns?
The only thing that I found here is resizeColumnToContents(), but this method will make me call it for every column. Isn't there something else?
Printable View
How can I make a QTreeView to auto-adjust the wigth of the columns?
The only thing that I found here is resizeColumnToContents(), but this method will make me call it for every column. Isn't there something else?
See QHeaderView::setResizeMode() with QHeaderView::ResizeToContents.
Code:
(self.ui.qtreeview.header()).setResizeMode(3)
That works great :)! But now I have another 2 problems. The first one is that I can't hide one of the columns, I tried with this:
Code:
index = (self.ui.qtreeview.header()).visualIndex(4) (self.ui.qtreeview.header()).setSectionHidden(index, True)
The second problem is that I have some qstandarditems that have really long text, and when the text-column is expanded according to the size of the text, the QTreeView will become... scrollable (horizontally). How can I prevent that?
Great,did the trick perfectlly. I also got the first one. I just had to say to the model that it'll have 5 columns, and then I hidded them withCode:
(self.ui.cList.header()).resizeSections(1)
Code:
.setSectionHidden(int, True)
Really thanks wysota!