[PyQt] using itemDoubleClicked with pyqt

Phil Thompson phil at riverbankcomputing.com
Wed Jun 23 08:46:21 BST 2010


On Wed, 23 Jun 2010 09:40:09 +0200, "Christopher M. Nahler"
<christopher.nahler at papermodels.at> wrote:
> I have problems using a signal. In the code below I create a QListWidget 
> where I would like to act upon doubleClicking an item.
> 
> In the documentation I have found the signal "itemDoubleClicked".  
> (http://doc.qt.nokia.com/4.6/qlistwidget.html#itemDoubleClicked)
> But somehow I am not using it right. What am I doing wrong?
> 
> thanks in advance
> Chris
> 
> 
> 
> import sys
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
> 
> itemList = ["One",
>               "Two",
>               "Three",
>               "Four",
>               "Five"]
> 
> class ListDlg(QDialog):
> 
>      def __init__(self, name, parent=None):
>          super(ListDlg, self).__init__(parent)
> 
>          self.myList = QListWidget()
>          self.myList.addItems(itemList)
>          self.myList.setCurrentRow(0)
> 
>          layout = QHBoxLayout()
>          layout.addWidget(self.myList)
>          self.setLayout(layout)
>          self.connect(self.myList, SIGNAL("itemDoubleClicked(*item)"), 
> self.processItem)
> 
>      def processItem(self, item):
>          print(item.text())
> 
> if __name__ == "__main__":
>      app = QApplication(sys.argv)
>      form = ListDlg("Listdialog")
>      form.exec_()

The signal signature is "itemDoubleClicked(QListWidgetItem *)"

Phil


More information about the PyQt mailing list