[PyQt] connection to list view and combo pyqt

David Boddie dboddie at trolltech.com
Wed Jan 23 18:16:52 GMT 2008


On Wed Jan 23 18:01:22 GMT 2008, Peter Liedler wrote:

> > You need to connect the selection model's signal to the titleSelected()
> > slot:
> > 
> >     self.connect(self.listViewTitle.selectionModel(),
> >         SIGNAL("selectionChanged(QItemSelection, QItemSelection)"),
> >         self.titleSelected)

> Sorry, no sucess here. I don't get it.

One thing that was strange in your example was that you were subclassing
QAbstractListModel, but calling the __init__() method of the
QAbstractTableModel.

Anyway, here's a simple, complete example that should work:


import sys
from PyQt4.QtCore import QObject, SIGNAL
from PyQt4.QtGui import *

def slot(selected, deselected):

    print len(selected), "items selected"
    print len(deselected), "items deselected"


if __name__ == "__main__":

    app = QApplication(sys.argv)
    model = QStandardItemModel()
    for i in range(10):
        model.appendRow([QStandardItem("Item %i" % i)])
    
    listView = QListView()
    listView.setModel(model)
    listView.show()
    
    QObject.connect(listView.selectionModel(),
        SIGNAL("selectionChanged(QItemSelection, QItemSelection)"),
        slot)
    
    sys.exit(app.exec_())


Does that help in any way?

David
-- 
David Boddie
Lead Technical Writer, Trolltech ASA


More information about the PyQt mailing list