how can i make the column width enough fit for the content in QTreeWidget?
-
void QTreeView::resizeColumnToContents(int column)
It's a slot, so when you add data, call it and it will do it for you ;-)
-
void QTreeView::resizeColumnToContents(int column)
It's a slot, so when you add data, call it and it will do it for you ;-)
QTreeView::resizeColumnToContents(int column)
If of interest to anyone in the future, iterating over the columns and applying this is quite trivial:
#!/usr/bin/env python3.13 import \ builtins, \ PyQt6.QtWidgets self.tree_widget = PyQt6.QtWidgets.QTreeWidget() tree_widget_header_labels: builtins.list = ["Name", "Location"] self.tree_widget.setHeaderLabels(tree_widget_header_labels) # Iteration: for i in builtins.range(builtins.len(tree_widget_header_labels)): self.tree_widget.resizeColumnToContents(i)