QTreeWidget activates element signals

I need to do some action when an element in a QTreeWidget is activated, but the following code does not produce the 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 activate an element correctly?

Thanks in advance, Serge

+3
source share
1 answer

If you look at the documentation , the description of the signal you are looking for has an asterisk.

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

This means that your connection call should look like this:

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

PyQt has a nice new API for connecting signals (since version 4.6, I think). I recommend using it.

self.itemActivated.connect(self.editCell)
+7
source

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


All Articles