[PyQt] Editing multiple items in QTreeView delegate

Hans-Peter Jansen hpj at urpla.net
Wed Apr 6 09:14:59 BST 2011


On Wednesday 06 April 2011, 02:43:38 James Polk wrote:
> I have a curious dilemma I can't seem to find any information about
> in the docs...
>
> I have a QTreeView and a delegate...
> The items in the QTreeView have columns of similar data.  When I set
> the selection behaviour to multiSelect (actually called
> ExtendedSelect) I can pick a single column of numbers that all have
> either a "1" in them.  I can then CTRL-click and change one of them
> from "1" to "0"...while all of them are still highlighted/selected.
>
> What I want to do is to simultaneously change all of them from 1 to 0
> in one fell swoop. In the delegate though...if I try to use
>
>     indices = treeView.selectedIndexes()
>
> it of course doesn't know anything about "treeView"....how can I pass
> to the delegate some variable that contains an
> address/pointer/reference to the QTreeView, so that I can query all
> the selected items.  I'm trying to make this work in the
> "setModelData" of the delegate.

The question is, why so? Since the treeview selection is a "view" thing, 
you should handle the selection there, e.g. by subclassing and 
reimplementing the QAbstractItemView.selectionChanged() method. 

Of course, you can add some convenience interface to the model to handle 
the bulk changes there.

Pete


More information about the PyQt mailing list