[PyQt] Editing multiple items in QTreeView delegate

James Polk jpolk5001 at yahoo.com
Wed Apr 6 18:34:24 BST 2011

Well I found a solution and thought I would share it...
Probably not the most elegant, but it does work..

Works by using an import global variable (told you it wasn't elegant ;-)

I created a file named "ms.py" and inside is a single line:


and that's all.

In my main.py,...I "import ms" at the top.  Later, I set the variable by...

     ms.MyTreeView = self.treeView

Then in my delegate file, delegate.py, I also add "import ms" at the top.
And then later, in the setModelData() function,  after checking selectionMode()
to make sure it's in multiSelect,...and after handling the "main" selection,I do a

      indices = ms.MyTreeView.selectedIndexes()

and loop thru them setting their value to the value of the main selection...

A side note,...when a treeView's selectionMode is set to 3 (Extended Selection),
one can pull a vertical pick from top to bottom, highlighting multiple items in a single
column.  Then, while holding down CTRL, you can double-click selection one item
out of this group.  This will pass this CTRL-selection to the delegate and remove its
index from the "indices" returned above.  Which is good, so you don't double-set
it's value.  When you hit "enter", the code will take the value of the CTRL-selection
and apply it to all the others who are still highlighted, making a nice clean sweep
and saving lots of keystrokes if you need to change a lot of items.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110406/4559fadc/attachment.html>

More information about the PyQt mailing list