8

I am using a QTreeWidget to display items in categories. Items will use several columns, but I want categories (ie. root items) to use the full width of the widget.

How can I do that?

And a piece of my code:

class BugsList(QtGui.QDialog):
    def __init__(self, parent, reports):
        super(BugsList, self).__init__(parent) # Call QDialog constructor
        self._tree = QtGui.QTreeWidget(self)
        self._tree.setColumnCount(NUMBER_OF_COLUMNS)
        # ...
        for category, bugs in reports:
            category_widget = QtGui.QTreeWidgetItem(self._tree, [category])
            # ...

Here is a screenshot of the current state of my application: screenshot

Valentin Lorentz
  • 9,556
  • 6
  • 47
  • 69

1 Answers1

7

Fixed with using QTreeWidgetItem::setFirstColumnSpanned.

Valentin Lorentz
  • 9,556
  • 6
  • 47
  • 69
  • 1
    Note that this only works after you attach the item to its parent, so that it does actually obtain an index in the underlying item model of the `QTreeWidget`. – Ruslan Nov 10 '20 at 12:06