[Interest] QTreeWidget event processing
alfa
alfarobi0161 at yahoo.com
Thu Jan 30 09:40:23 CET 2014
Hi all,
I would like to have the following feature when using
QTreeWidget via signal and slot mechanism. As an item(item_0) is
entered, then a slot will be connected(that simply sets a value on
(item_1)). To achieve that, I did the following:
self.treeWidget.itemEntered(item_0, 0).connect(self.trigger_result)
and the UI complete code is as below:
class Ui_MainWindow(object):
def setupUi(self, MainWindow): MainWindow.setObjectName(_fromUtf8("MainWindow")) MainWindow.resize(480, 471) self.centralWidget = QtGui.QWidget(MainWindow) self.centralWidget.setObjectName(_fromUtf8("centralWidget")) self.treeWidget = QtGui.QTreeWidget(self.centralWidget) self.treeWidget.setGeometry(QtCore.QRect(20, 20, 431, 321)) self.treeWidget.setObjectName(_fromUtf8("treeWidget")) item_0 = QtGui.QTreeWidgetItem(self.treeWidget) item_1 = QtGui.QTreeWidgetItem(item_0) item_1.setFlags(QtCore.Qt.ItemIsSelectable|QtCore.Qt.ItemIsEditable|QtCore.Qt.ItemIsDragEnabled|QtCore.Qt.ItemIsUserCheckable|QtCore.Qt.ItemIsEnabled) item_1 = QtGui.QTreeWidgetItem(item_0) #redundant item_1.setFlags(QtCore.Qt.ItemIsSelectable|QtCore.Qt.ItemIsEditable|QtCore.Qt.ItemIsDragEnabled|QtCore.Qt.ItemIsUserCheckable|QtCore.Qt.ItemIsEnabled) #redundant item_0 = QtGui.QTreeWidgetItem(self.treeWidget) #redundant item_0 = QtGui.QTreeWidgetItem(self.treeWidget) #redundant
MainWindow.setCentralWidget(self.centralWidget) self.menuBar = QtGui.QMenuBar(MainWindow) self.menuBar.setGeometry(QtCore.QRect(0, 0, 480, 23)) self.menuBar.setObjectName(_fromUtf8("menuBar")) MainWindow.setMenuBar(self.menuBar) self.mainToolBar = QtGui.QToolBar(MainWindow) self.mainToolBar.setObjectName(_fromUtf8("mainToolBar")) MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar) self.statusBar = QtGui.QStatusBar(MainWindow) self.statusBar.setObjectName(_fromUtf8("statusBar")) MainWindow.setStatusBar(self.statusBar) self.retranslateUi(MainWindow) self.treeWidget.itemEntered(item_0, 0).connect(self.trigger_result) QtCore.QMetaObject.connectSlotsByName(MainWindow) def trigger_result(self): self.treeWidget.topLevelItem(0).child(1).setText(1, '99') def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
self.treeWidget.headerItem().setText(0, QtGui.QApplication.translate("MainWindow", "Property", None, QtGui.QApplication.UnicodeUTF8)) self.treeWidget.headerItem().setText(1, QtGui.QApplication.translate("MainWindow", "Value", None, QtGui.QApplication.UnicodeUTF8)) __sortingEnabled = self.treeWidget.isSortingEnabled() self.treeWidget.setSortingEnabled(False) self.treeWidget.topLevelItem(0).setText(0, QtGui.QApplication.translate("MainWindow", "Main", None, QtGui.QApplication.UnicodeUTF8)) self.treeWidget.topLevelItem(0).child(0).setText(0, QtGui.QApplication.translate("MainWindow", "Mass flow", None, QtGui.QApplication.UnicodeUTF8)) self.treeWidget.topLevelItem(0).child(1).setText(0, QtGui.QApplication.translate("MainWindow", "Efficiency", None, QtGui.QApplication.UnicodeUTF8)) self.treeWidget.topLevelItem(1).setText(0, QtGui.QApplication.translate("MainWindow", "Inlet/Inner part", None, QtGui.QApplication.UnicodeUTF8))
self.treeWidget.topLevelItem(2).setText(0, QtGui.QApplication.translate("MainWindow", "Outlet/Outer part", None, QtGui.QApplication.UnicodeUTF8)) self.treeWidget.setSortingEnabled(__sortingEnabled)
However, I receive the following error:
line 283, in setupUi
self.treeWidget.itemEntered(item_0, 0).connect(self.trigger_result)
I understand that if I do:
self.treeWidget.itemEntered.connect(self.trigger_result)
it will work, but the problem is, any cell or item entered, it will definitely call the slot, which is not what I want.
Also, I've tried:
self.treeWidget.itemEntered(self.treeWidget.topLevelItem(0).child(0), 1).connect(self.trigger_result)
it doesn't work either.
Attached is the code in Python. Please shed some light on this.
Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140130/f271720d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mainwindow.py
Type: text/x-python
Size: 3987 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140130/f271720d/attachment.py>
More information about the Interest
mailing list