Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expanding width of column in QTreeWidget dynamically

Using PySide, I am developing a small application. In my application, I am using QTreeWidget, to show form like data. This QTreeWidget has single column.My problem is that QTreeWidget not showing horizontal scroll bar when its element expands in horizontal direction. Has anybody have any idea about this issue?

After trying some things I noticed that I need to expand width of column dynamically. Is it possible?

Note: I have tried 'setColumnWidth', it is working fine. But I want to do it dynamically.

Thanks in advance

like image 812
userx Avatar asked Dec 06 '22 02:12

userx


2 Answers

You need to resize to contents as well as switching off stretch last section:

    treewidget.header().setResizeMode(QtGui.QHeaderView.ResizeToContents)
    treewidget.header().setStretchLastSection(False)
like image 55
ekhumoro Avatar answered Dec 09 '22 13:12

ekhumoro


In PySide2 you can use this:

header = self.treeWidget.header()
header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
header.setStretchLastSection(False)
header.setSectionResizeMode(5, QtWidgets.QHeaderView.Stretch)
like image 30
Rajiv Sharma Avatar answered Dec 09 '22 14:12

Rajiv Sharma