Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Qt QListWidget Double Clicked

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.

like image 590
Cloak Avatar asked Oct 13 '12 20:10

Cloak


1 Answers

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).

like image 167
ekhumoro Avatar answered Oct 18 '22 12:10

ekhumoro