Re: [PyQt] connection to list view and combo pyqt
I am still fighting to get connected to a selectionChanged signal of a listView. If I understand the qt documentation, the QItemSelection is generated automatically by filling the index to the model and defining the model to the list. I think I do so by: Defining the model class: class myListModel(QAbstractListModel): def __init__(self, datain, parent=None, *args): datain: a list where each item is a row QAbstractTableModel.__init__(self, parent, *args) self.listdata = datain In the main view I call a subfunction to set the index to the model: self.listModel = myListModel(TitleTrack, self) #init listView self.listViewTitleFill() Where TitleTrack is a python list. def listViewTitleFill(self): init ListViews and build list models self.listModel = myListModel(TitleTrack, self) self.listViewTitle.setModel(self.listModel) self.listViewTitle.setSelectionMode(QAbstractItemView.SingleSelection) This part works fine. The list is filled and I can select items in there. self.connect(self.listViewTitle, SIGNAL(selectionChanged(QItemSelection, QItemSelection)), self.titleSelected) With this connect string I try to connect to the signal that is emitted when the selection is changed. But it is never called. What am I missing here. Thanks Peter On Son, 2008-01-20 at 01:26 +0100, David Boddie wrote: On Sat Jan 19 13:41:12 GMT 2008, Peter Liedler wrote: In my main view I have several connect strings to buttons and checkBoxes. They work fine. self.connect(self.checkBoxRipLongest, SIGNAL(clicked()), self.toggleRipLongest) self.connect(self.listViewTitle, SIGNAL(selectionChanged()), self.titleSelected) self.connect(self.comboBoxLanguage, SIGNAL(currentIndexChanged()), self.languageSelected) Are you sure they all work? The problem below would make me suspicious that the third one wouldn't work. But the connection string to a QComboBox and a QListView do not work. What am I doing wrong here? self.connect(self.listViewTitle, SIGNAL(selectionChanged()), self.titleSelected) self.connect(self.comboBoxLanguage, SIGNAL(currentIndexChanged()), self.languageSelected) I want to call the self.titleSelected function when another index in the list is filled, but obviously the signal is never emitted. (I have put a print statement there). Same with the comboBox. You need to include the argument types in the signal declaration. For example, currentIndexChanged() is actually available in two forms: currentIndexChanged(int) currentIndexChanged(const QString) I believe you can simplify the second form to currentIndexChanged(QString) if that's the one you want. Which class provides the selectionChanged() signal? Please forgive me to ask such a simple question. That's what we're here for! David ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] connection to list view and combo pyqt
Sorry, no sucess here. I don't get it. Peter On Mit, 2008-01-23 at 18:28 +0100, David Boddie wrote: On Wed Jan 23 17:08:15 GMT 2008, Peter Liedler wrote: I am still fighting to get connected to a selectionChanged signal of a listView. I think there's been some confusion about what actually emits the selectionChanged() signal. It's actually the list view's selection model: http://www.riverbankcomputing.com/Docs/PyQt4/html/qabstractitemview.html#selectionModel The signal is described here: http://www.riverbankcomputing.com/Docs/PyQt4/html/qitemselectionmodel.html#selectionChanged If I understand the qt documentation, the QItemSelection is generated automatically by filling the index to the model and defining the model to the list. I'm not sure what you mean. The selection model (which is set up by the view) keeps track of the selected indexes in the model. I think I do so by: Defining the model class: class myListModel(QAbstractListModel): def __init__(self, datain, parent=None, *args): datain: a list where each item is a row QAbstractTableModel.__init__(self, parent, *args) self.listdata = datain This looks OK. In the main view I call a subfunction to set the index to the model: self.listModel = myListModel(TitleTrack, self) #init listView self.listViewTitleFill() Where TitleTrack is a python list. So, you're putting data into the model. def listViewTitleFill(self): init ListViews and build list models self.listModel = myListModel(TitleTrack, self) self.listViewTitle.setModel(self.listModel) self.listViewTitle.setSelectionMode( QAbstractItemView.SingleSelection) This part works fine. The list is filled and I can select items in there. OK. You're defining the model again here, of course... Now, this is the problem part: self.connect(self.listViewTitle, SIGNAL(selectionChanged(QItemSelection, QItemSelection)), self.titleSelected) With this connect string I try to connect to the signal that is emitted when the selection is changed. But it is never called. What am I missing here. You need to connect the selection model's signal to the titleSelected() slot: self.connect(self.listViewTitle.selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), self.titleSelected) Does that work? David ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] connection to list view and combo pyqt
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 ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] connection to list view and combo pyqt
On Sat Jan 19 13:41:12 GMT 2008, Peter Liedler wrote: In my main view I have several connect strings to buttons and checkBoxes. They work fine. self.connect(self.checkBoxRipLongest, SIGNAL(clicked()), self.toggleRipLongest) self.connect(self.listViewTitle, SIGNAL(selectionChanged()), self.titleSelected) self.connect(self.comboBoxLanguage, SIGNAL(currentIndexChanged()), self.languageSelected) Are you sure they all work? The problem below would make me suspicious that the third one wouldn't work. But the connection string to a QComboBox and a QListView do not work. What am I doing wrong here? self.connect(self.listViewTitle, SIGNAL(selectionChanged()), self.titleSelected) self.connect(self.comboBoxLanguage, SIGNAL(currentIndexChanged()), self.languageSelected) I want to call the self.titleSelected function when another index in the list is filled, but obviously the signal is never emitted. (I have put a print statement there). Same with the comboBox. You need to include the argument types in the signal declaration. For example, currentIndexChanged() is actually available in two forms: currentIndexChanged(int) currentIndexChanged(const QString) I believe you can simplify the second form to currentIndexChanged(QString) if that's the one you want. Which class provides the selectionChanged() signal? Please forgive me to ask such a simple question. That's what we're here for! David ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt