I have a QTreeWidget, which I noticed has the functionality to drag the column headers from their original location to somewhere new. I want to use this feature in my application, but when I drag a column header to a new location, the QTreeWidget does not seem to retain the column changes in any of the QTreeWidgetItems.
I tried to loop through the columns and print out the text of each column in the QTreeWidget's header item after a header was dragged to a new location, but this did not seem to retain any of the changes. Next, I tried overriding the QTreeWidget::dropEvent
function, but I noticed that this function is only activated when a QTreeWidgetItem is dragged to a new location, not a column.
Debug code to print out the text of each column in the HeaderItem:
column_count = self.ui.treeWidget.headerItem().columnCount()
for ii in range(column_count):
print(self.ui.treeWidget.headerItem().text(ii))
I don't need to catch the change right when it happens, I just want to be able to find whatever changes were applied to the QTreeWidget columns at some point in time after one of these column drag and drops. I would expect the debug code above to print out the text of the newly ordered headerItem columns, but it still prints the header columns in the old order before any columns were dragged to a new location.
QHeaderView::logicalIndex
andQHeaderView::visualIndex
. – G.M.QHeaderView::logicalIndex
to get the headers with their new index after they were modified by the user moving them. I will update the question with an answer and the modified debug code. – jkulskis