[PyQt] using itemDoubleClicked with pyqt
Mark Summerfield
list at qtrac.plus.com
Wed Jun 23 10:10:59 BST 2010
Hi Chris,
On 2010-06-23, Christopher M. Nahler wrote:
> On 23.06.2010 09:46, Phil Thompson wrote:
> > On Wed, 23 Jun 2010 09:40:09 +0200, "Christopher M. Nahler"
[snip]
> > The signal signature is "itemDoubleClicked(QListWidgetItem *)"
> >
> > Phil
>
> The way I understand this is that the signal passes a pointer to an
> item, right? So what is the correct way to setup the connection? I have
> tried with SIGNAL("itemDoubleClicked(item*)" and
> SIGNAL("itemDoubleClicked(item *)" but that also did not work.
The thing about using Qt signals is that you must specify the signal's
_signature_, i.e., the type(s) it takes, but not their parameter names.
This is a bit counter-intuitive for Python programmers since we're used
to using parameter names not types.
So,
self.connect(self.myList,
SIGNAL("itemDoubleClicked(*item)"), # WRONG
self.processItem)
must be written as:
self.connect(self.myList,
SIGNAL("itemDoubleClicked(QListWidgetItem*)"),
self.processItem)
The quoted string inside SIGNAL must be the name of the signal and its
parameter _types_. So for example, if you want to know when the current
row has changed you'd write (assuming that self.myList is a QListWidget):
self.connect(self.myList,
SIGNAL("currentItemChanged(QListWidgetItem*,QListWidgetItem*)"),
self.currentChanged)
and the currentChanged method would look like this:
def currentChanged(self, currentListItem, previousListItem):
pass
Hope that helps:-)
--
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
C++, Python, Qt, PyQt - training and consultancy
"Advanced Qt Programming" - ISBN 0321635906
http://www.qtrac.eu/aqpbook.html
A true story...
I ordered a Dell netbook with Ubuntu preinstalled. It arrived with no
OS at all and Dell's "support" said the don't supply Ubuntu any more.
Dell gave no apology, no solution, and no refund.
So I do *not* recommend Dell.
More information about the PyQt
mailing list