Python Qt QListWidget Double Clicked
Asked Answered
P

1

6

I want to add double clicked attribute for my QListWidget objects.

My command line does not work:

   self.connect(self.listWidget, QtCore.SIGNAL("itemDoubleClicked(QtGui.QListWidgetItem)"), self.showItem)

How to add double clicked attribute ? How to give object parameter to QtCore.SIGNAL.

Powerful answered 13/10, 2012 at 20:58 Comment(0)
B
10

The reason why the signal connection did not work, is that you are using the wrong signature for QListWidget.itemDoubleClicked. It should instead look like this:

self.connect(self.listWidget,
             QtCore.SIGNAL("itemDoubleClicked(QListWidgetItem *)"),
             self.showItem)

However, I would advise that you avoid using this method of connecting signals altogther, and switch to the new-style syntax instead. This would allow you to rewrite the above code like this:

self.listWidget.itemDoubleClicked.connect(self.showItem)

Which is not only simpler and cleaner, but also much less error-prone (in fact, an exception will be raised if the wrong signal name/signature is used).

Belvabelvedere answered 13/10, 2012 at 21:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.