Hello,
What's the proper way to compare two QItemSelection instances? It seems
that using the == operation always returns False.
Comparing their indexes() can do the job but it seems a bit redundant.
The attached code tries to demonstrate the problem. Make any selection
in the view and check the result of the three prints.
The first one will always return False, while the second and third one
will always return True.
Am I doing something wrong?
regards
Zoltan
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class TableView(QTableView):
def __init__(self, parent=None):
super(TableView, self).__init__(parent)
self.resize(400, 400)
def selectionChanged(self, selected, deselected):
super(TableView, self).selectionChanged(selected, deselected)
self._selection1 = self.selectionModel().selection()
self._selection2 = self.selectionModel().selection()
self._selectedIndexes1 = self.selectionModel().selectedIndexes()
self._selectedIndexes2 = self.selectionModel().selectedIndexes()
print 'cmp selection', self._selection1 == self._selection2
print 'cmp selection indexes', self._selection1.indexes() ==
self._selection2.indexes()
print 'cmp selectedIndexes', self._selectedIndexes1 ==
self._selectedIndexes2
if __name__ == '__main__':
import sys
import random
app = QApplication(sys.argv)
model = QStandardItemModel(10, 3)
tableView = TableView()
tableView.setModel(model)
for row in range(10):
for column in range(3):
index = model.index(row, column, QModelIndex())
model.setData(index, random.randint(0, 100))
tableView.setWindowTitle("Tableview")
tableView.show()
sys.exit(app.exec_())
_______________________________________________
PyQt mailing list [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt