Search code examples
pyqtqtreewidget

QTreeWidget created at runtime failed to emit itemDoubleClicked signal


I made a widget that inherits from QTreeWidget and successfully created an instance and added it to a tab control. However, I am trying to capture the itemDoubleClicked signal, but failed. I tried to put the connect statement in either the form that has the tab control, it failed to emit signal, then I put the connect inside my custom widget, it failed also. So, not sure how to connect to a tree widget that is created at runtime.

from within my custom QTreeWidget class: QtCore.QObject.connect(self, QtCore.SIGNAL('itemDoubleClicked(QTreeWidgetItem, int)'), self.edit_treeitem)

or from within the tab control:

QtCore.QObject.connect(self.mytree, QtCore.SIGNAL('itemDoubleClicked(QTreeWidgetItem, int)'), self.edit_treeitem)

Can anyone help?


Solution

  • Use the new style of signal connection:

    self.mytree.itemDoubleClicked.connect(self.edit_treeitem)