[PyQt] connection to list view and combo pyqt
Peter Liedler
peter at liedler.at
Wed Jan 23 17:08:15 GMT 2008
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 list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
More information about the PyQt
mailing list