14
votes

Does anyone know if its possible to select multiple items on a QTreeWidget and how to go about enabling the multiple selection?

All the items I want to be selectable are top level QTreeWidgetItems and all their children are set to be disabled (i.e QTreeWidgetItem.setDisabled(True) )

2
HA! Found it -> QTreeWidgetItem.setSelectionMode( QAbstractItemView.MultiSelection ) I found that bit of code while trying to make a multi selectable QListW - Jay

2 Answers

17
votes

It is, you'll want to call setSelectionMode during init to enable QAbstractItemView::MultiSelection. QTreeView/QTreeWidget inherit QAbstractItemView, so it is available.

Then to disable the items, just hook on to QTreeWidgets.itemSelectionChanged() signal.

1
votes

I think below will help:

youQTreeWidget.setSelectionMode(QGui.QAbstractView.MultiSelection)