Python Qt QListWidget Double Click

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

My command line is not working:

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

How to add double click attribute? How to pass an object parameter to QtCore.SIGNAL.

+4
source share
1 answer

The reason the connection to the signal does not work is because you are using the wrong signature for QListWidget.itemDoubleClicked . It should look like this:

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

However, I would advise you to avoid using this altogther signal hooking method and switch to the new style syntax instead. This will allow you to rewrite the above code as follows:

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

Which is not only simpler and cleaner, but also much less prone to errors (in fact, if an incorrect signal name / signature is used, an exception will be thrown).

+7
source

Source: https://habr.com/ru/post/1439579/


All Articles