[PyQt] Error when double clicking
Phil Thompson
phil at riverbankcomputing.com
Tue Nov 17 10:08:44 GMT 2009
On Tue, 17 Nov 2009 10:32:01 +0100, Mads Ipsen <mpi at comxnet.dk> wrote:
> dizou wrote:
>> I have a class that inherits QTreeWidget, in the __init__ I am trying to
>> connect a double click with a function:
>>
>>
>> class TreeArea(QTreeWidget):
>> def __init__(self, parent):
>> .
>> .
>> .
>> self.connect(self, SIGNAL("itemDoubleClicked(QTreeWidgetItem
>> *)"),
>> self.edit)
>>
>> def edit(self, item):
>> .
>> .
>> .
>>
>> However, when I run the program and click on an item I get this error:
>> TypeError: edit() takes exactly 2 arguments (4 given)
>>
>> Also, what is the PyQt equivalent of:
>> setEditTriggers(QAbstractItemView::NoEditTriggers)
>>
> I also get the same error with the example included below. Any clues?
>
>
> import sys
> from PyQt4 import QtCore, QtGui
>
>
> class TreeWidget(QtGui.QTreeWidget):
> def __init__(self, parent=None):
> QtGui.QTreeWidget.__init__(self, parent)
>
> # Add an item
> item = QtGui.QTreeWidgetItem(['1'], 0)
> self.addTopLevelItem(item)
>
> # Connect
> self.connect(self, QtCore.SIGNAL('itemDoubleClicked (
> QTreeWidgetItem *, int)'), self.edit)
>
> def edit(self, item, column):
> print 'Clicked'
>
> if __name__ == "__main__":
> app = QtGui.QApplication(sys.argv)
>
> widget = TreeWidget()
> widget.show()
>
> sys.exit(app.exec_())
You are reimplementing QAbstractItemView.edit(). Call your method something
else.
Phil
More information about the PyQt
mailing list