[PyQt] trivial question regarding standarditemmodels
Greg Smith
gsmith at troublemakerstudios.com
Fri Jun 12 15:57:45 BST 2009
Nevermind figured out what my problem was, it was unrelated to PyQt and
a threading issue.
________________________________
From: pyqt-bounces at riverbankcomputing.com
[mailto:pyqt-bounces at riverbankcomputing.com] On Behalf Of Greg Smith
Sent: Friday, June 12, 2009 9:36 AM
To: pyqt
Subject: RE: [PyQt] trivial question regarding standarditemmodels
Okay tell me if I'm doing something wrong, I am doing some basic test
executions on button logic
Here is what I got so far
Button_pressed(self):
sel_idxs = self.ui.myListView.selectedIndexes()
for i in sel_idxs:
msg = 'row: %s, col: %s' % (i.row(), i.column())
print msg
so in my listview I have 4 items, I select the first and third item
which should give me row indexes 0 and 2, what gets printed is this:
row: 2, col:0
row: 2, col:0
...umm that's not right. I try other selection combinations, and it
seems that only the last item that was selected, that row index gets
returned
Only time it really works is if I make single selections. But I want the
user to be able to select which ever and the appropriate list of indexes
is returned.
I'm at a loss on this one, I thought I had my problem pegged until I did
this test.
Any clues? This is beginning to drive me nuts!
Greg
________________________________
From: pyqt-bounces at riverbankcomputing.com
[mailto:pyqt-bounces at riverbankcomputing.com] On Behalf Of Greg Smith
Sent: Thursday, June 11, 2009 6:12 PM
To: pyqt
Subject: [PyQt] trivial question regarding standarditemmodels
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/e4e58974/attachment.html
More information about the PyQt
mailing list