I have a QTreeView. I'd like to alter the way selection works. When a user selects an intermediate node, I need to select all subordinate nodes as well, and possibly change selection status of superior nodes in the tree (data or selection status).

I've tried working with the selectionChanged signal, but that induces some undesirable feedback (selection changes at this stage cause another iteration of event loop processing, and it can be difficult to differentiate user vs. programmatic changes in subsequent invocation of the selectionChanged signal). I'd like to have a method that gets called *before* anything is selected, so that I can decide what (if anything) gets selected/deselected. Is this possible?

Should I subclass QTreeView and write my own selectionCommand() method? The (minimal) documentation for this hints at doing this to "define your own selection behavior" but I'm not sure if that really means "define your own QAbstractItemView::SelectionBehavior" which isn't what I really want.

What's the right way to do this?