View Full Version : AutoAdjust columns in a QTreeView
alexandernst
26th July 2009, 21:10
How can I make a QTreeView to auto-adjust the wigth of the columns?
The only thing that I found here (http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qtreeview.html) is resizeColumnToContents(), but this method will make me call it for every column. Isn't there something else?
wysota
26th July 2009, 22:18
See QHeaderView::setResizeMode() with QHeaderView::ResizeToContents.
alexandernst
26th July 2009, 23:44
(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:
index = (self.ui.qtreeview.header()).visualIndex(4)
(self.ui.qtreeview.header()).setSectionHidden(inde x, 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?
wysota
27th July 2009, 07:36
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?
Don't set the resizeMode policy to ResizeToContents for that column (or set it to something else).
alexandernst
27th July 2009, 10:51
Great,
(self.ui.cList.header()).resizeSections(1) 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 with
.setSectionHidden(int, True)
Really thanks wysota!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.