How to capture resizing of QTreeWidget columns

1.2k Views Asked by At

I need a column in my QTreeWidget which's width is always x pixels.

So i want to capture a resize of my QTreeWidget columns, to set the with back to my x on resize by user. But i can't find any Signal like columnWidthChanged.

Is there any way to call a function/slot when a columns with is changed? Or is there any other solution?

2

There are 2 best solutions below

1
sebastian On BEST ANSWER

Instead of connecting to the sectionResized signal and reverting resizes the user made, why not prevent users from resizing the column in the first place, via

treeWidget.header().setSectionResizeMode(QHeaderView::Fixed)

or prevent resizing only individual columns via

treeWidget.header().setSectionResizeMode(colIdx, QHeaderView::Fixed)

That's easier to implement and much more "natural" to the user.

0
Haselnussstrauch On

The Signal is emitted by the header of the QTreeWidget. It's QTreeWidget.header().sectionResized(int column, int oldsize, int newsize)