[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    [PyQt] comparing two QItemSelection always return False?
From:       Zoltan Szalai <flc () freemail ! hu>
Date:       2010-06-30 18:35:02
Message-ID: 4C2B8E56.9000501 () freemail ! hu
[Download RAW message or body]

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

["tableview_selection.pyw" (text/plain)]

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    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic