[PyQt] Re: QTableView selected item signals via QItemSelectionModel
Alberto Berti
alberto at metapensiero.it
Wed Nov 19 22:15:54 GMT 2008
>>>>> "Scott" == Scott Frankel <frankel at circlesfx.com> writes:
Scott> Hello,
Scott> What's the proper way to identify which row of a QTableView
Scott> instance a user may have selected?
The use of the QItemSelectionModel seems the right approach to me. The
problem is then to identify what you really need, because the selection
model carries both the information of the "current" ModelIndex which has
user input focus AND the possible list of ModelIndexes (read cells)
highlighted to be the subject of the next operation. Using
'selectionChanged' helps when latter is the needed information, where
'currentChanged' gives you info about the former.
I did not run your code, but probably this patch should correct your
initial problem with the signal:
--- selectionModel.py 2008-11-19 22:36:44.789397158 +0100
+++ selectionModel.py.alberto 2008-11-19 22:52:03.341742383 +0100
@@ -112,13 +112,14 @@
# signals/slots
# ------------------------------------------------
- self.connect(self.theSelectionModel, QtCore.SIGNAL("selectionChanged()"), self.getSelection)
+ self.connect(self.theSelectionModel,
+ QtCore.SIGNAL("selectionChanged(QItemSelection, QItemSelection)"), self.getSelection)
# methods
# ------------------------------------------------
- def getSelection(self):
+ def getSelection(self, selected, deselected):
print "getSelection() ..."
index = self.theSelectionModel.currentIndex()
hope it helps
Alberto
More information about the PyQt
mailing list