[PyQt] trivial question regarding standarditemmodels

Greg Smith gsmith at troublemakerstudios.com
Fri Jun 12 00:12:12 BST 2009


Hey everyone. I have a QListView widget that is populated by a
QStandardItemModel, which I populated using the appendRow method with a
list containing QStandardItems. 

My question is that I am creating a gui to where the user can select
multiple Items in the listview and press a button to remove those items
from the list. 

 

Now for the most part, I figured the logic theory out in my head on how
to do this, where I am stuck is executing the logic within the context
of an ItemModel. Up to this point 

I've learned enough about ItemModels to get me in trouble, but not
enough to have a complete understanding of whats actually happening.
Plus all the lists I made previously only used 

Single selection and I was able to get the selection I needed from a
selectionChanged method. I also figured out how to set the selection of
a ListView  programmatically with not too much trouble. However where I
am stuck, is trying to figure out how to access what row information
based off of whats selected or not selected in its related listview
object. 

 

Here is what I plan on doing in my button logic

 

1. newItemModel = existingItemModel()

2. for rowInt in  range(existingModel.rowCount):

3.     rowIndex = existingModel.index(rowInt, 0)

4.     if  rowIndex not in listView.selectedIndexes():

5.         newItemModel.addRow(existingItemModel.takeRow(rowInt)

6.  listView.setModel(newItemModel)

 

Where I think I am getting hung up is on row 3 or 4, because I don't'
know if that maintains a 1 to 1 relation ship between the QModelIndex
item created by the index() method and the QModelIndex item that is
created from the selectedIndex() method.  Again, like I said, I know
enough to get in trouble. This could be an entirely wrong approach.

 

So not sure what to do actually, so any advice on the matter would be
truly appreciated.

 

Greg

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090612/40a251b1/attachment.html


More information about the PyQt mailing list