14

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) )

Jay
  • 3,373
  • 6
  • 38
  • 55
  • 1
    HA! Found it -> QTreeWidgetItem.setSelectionMode( QAbstractItemView.MultiSelection ) I found that bit of code while trying to make a multi selectable QListW – Jay Aug 03 '11 at 12:13

2 Answers2

17

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.

Matteo Italia
  • 123,740
  • 17
  • 206
  • 299
Mike Ramirez
  • 10,750
  • 3
  • 26
  • 20
  • 1
    Thanks... I managed to find the answer already but since I dont have enough points I couldn't answer my own question so I just left a comment answering it. Thanks for taking the time though :) Its very appreciated – Jay Aug 05 '11 at 07:16
  • Link is ded. But official docs are here anyway: http://doc.qt.io/qt-5/qabstractitemview.html#selectionMode-prop – Tomáš Zato Sep 11 '15 at 09:23
1

I think below will help:

youQTreeWidget.setSelectionMode(QGui.QAbstractView.MultiSelection)
zleung
  • 57
  • 4