[Qt-creator] QTreeWidget event processing

alfa alfarobi0161 at yahoo.com
Thu Jan 30 09:43:32 CET 2014


Hi Ziller,

Thanks for the information and I apologize for sending to the wrong mailing list. I've just sent there.

-alfa





On Thursday, January 30, 2014 4:14 PM, Ziller Eike <Eike.Ziller at digia.com> wrote:
 
Try the interest@ mailing list maybe, I don’t know if there might be some PyQt specific list, if there is, that might be even better suited…
This list is about using and developing Qt Creator.

Br, Eike

On Jan 30, 2014, at 6:05 AM, alfa <alfarobi0161 at yahoo.com> wrote:

> 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.
> <mainwindow.py>_______________________________________________

> Qt-creator mailing list
> Qt-creator at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/qt-creator

-- 
Eike Ziller, Senior Software Engineer - Digia, Qt

Digia Germany GmbH, Rudower Chaussee 13, D-12489 Berlin
Geschäftsführer: Mika Pälsi, Juha Varelius, Tuula Haataja
Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20140130/eed6c5b5/attachment.html>


More information about the Qt-creator mailing list