I am trying to restrict selection of a tree to a particular column.
I am using delegates heavily to create custom per-item-per-column behaviors, editors, etc. I was hoping I could somehow do this from a delegate by blocking an event or something similar. The problem is, I think i would have to create an entirely custom solution that mimics extended selection.
However, after a lot of searching and very few examples, it sounds like I want a custom QItemSelectionModel on my tree view. Is this assumption correct?
How do I create a custom QItemSelectionModel that will use the Extended Selection Mode but allow me to ignore or revert a selection if not in a particular column. In other words, clicking on another column should not change the selection (should not select or deselect)
I know how to add the selection model once I have it. I am asking for help implementing the derived class (unless this can be done with a connected signal).
I am using Python, but would value any help.
Thank you,
[EDIT:] I found these similar questions: http://lists.qt.nokia.com/pipermail/qt-interest/2010-September/027647.html
"Subclass QItemSelectionModel and reimplement both select methods to have the behaviour you want. Just ignore the parts of ranges with column > 0. ... Or maybe just reimplement flags() to make the item not selectable. I don't know if that will have any side effects."
I tried reimplementing flags on my QTreeWidgetItem, but it never got called:
def flags(self, index):
print index.column()
return super(DDOutlinerBaseItem, self).flags(index)
The following adjustment should work, in theory.
The above solution could use two separate methods and @pyqtSlot decorators to disambiguate the overloaded method names:
This avoids the need to check for instances of certain classes in the method implementations.