[PyQt] qtreeview vs qtreewidget selection model?

Andreas Pakulat apaku at gmx.de
Thu Oct 4 23:46:48 BST 2012


On Fri, Oct 5, 2012 at 12:20 AM, Jordan Olson <jorxster at gmail.com> wrote:
> So here's what's happening. I'm implementing a custom QTreeView model,
> and though I have it working pretty well, the one little peeve I
> haven't figured out is the way it handles selection-
> --any default list/table/tree widget that ships with PyQt (or most
> windows managers for that manager) have it so that when you left click
> on an unselected item, it *unselects* any other selection you have,
> unless you hold down Ctrl or Shift. Follow?
> But with my qtreeview widget, I've got it displaying my custom model,
> but it handles selection via mouse a little differently- clicking
> seems to merely toggle item selection, and left clicking on an
> unselected item doesn't deselect already selected items as you might
> expect.
> Can you give me a tip as to what methods I should be looking at? I
> have a hunch it has to do with selection Model, but can't figure out
> how to alter/implement this in pyQt.

No, the selection-model only keeps track of the selected indexes.
Which indexes are being selected upon clicking (with or without
modifiers) depends on the selection mode of the QTreeView (this
propery comes from the base class QAbstractItemView). IIRC the
behaviour you want is called ExtendedSelection in Qt.


More information about the PyQt mailing list