Search code examples
qtqtreewidgetqt5.2

How to capture resizing of QTreeWidget columns


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?


Solution

  • 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.