3

I need to do some actions when item in QTreeWidget activates, but following code doestn't gives me expected result:

class MyWidget(QTreeWidget):

    def __init__(self, parent=None):
        super(MyWidget, self).__init__(parent)
        self.connect(self, SIGNAL("activated(QModelIndex)"), self.editCell)


    def editCell(self, index):
        print index

or

 class MyWidget(QTreeWidget):

    def __init__(self, parent=None):
         super(MyWidget, self).__init__(parent)
         self.connect(self, SIGNAL("itemActivated(QTreeWidgetItem, int)"),
                      self.editCell)


     def editCell(self, item, column=0):
         print item

What am i doing wrong or how to hadnle item activation in the right way?

Thanks in advance, Serge

serge
  • 405
  • 9
  • 18

1 Answers1

7

If you look at the documentation the description of the signal you're looking for has an asterisk.

QTreeWidget::itemActivated(QTreeWidgetItem *item, int column)

This means your connect call should look like this:

self.connect(self, SIGNAL("itemActivated(QTreeWidgetItem*,int)"), self.editCell)

PyQt has a nice new API to connect signals (since version 4.6 I believe). I recommend using it.

self.itemActivated.connect(self.editCell)
Georg Schölly
  • 124,188
  • 49
  • 220
  • 267