0
我是Pyhthon和Qt的新手,因此這個基本問題。我想要的是,當我點擊QTreeWidget中的一個項目時,會調用一個事件處理程序,它告訴我哪個項目已被點擊。我試過的代碼是:如何在PyQt4的點擊反應QTreeWidget
self.dir_tree = QTreeWidget()
self.dir_tree.setColumnCount (3)
self.dir_tree.setHeaderLabels (("File", "Type", "Size"))
self.dir_tree.connect (dir_tree, SIGNAL ("itemClicked (QTreeWidgetItem*, int)"), self.onClickItem)
def onClickItem (self, column):
print (column)
這不運行,錯誤代碼是:
TypeError: arguments did not match any overloaded call:
QObject.connect(QObject, SIGNAL(), QObject, SLOT(),Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'function'
QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'function'
QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'function'
我在做什麼錯?還有一個與此有關的問題:我怎麼才能找出哪個項目被點擊?
我找不到這個教程,任何建議是值得歡迎的。
感謝您的任何幫助。