Re: [PyQt] identify a QTreeWidgetItem
Le mardi 23 octobre 2007, Michael Towers a écrit : alteo_gange wrote: print item.text(0), \n UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 11: ordinal not in range(128) I find this one of the most annoying things in PyQt, it confuses me terribly. I think in this case you can do (for example) print unicode(item.text(0)), \n (the original result from item.text() being a QString) But it may be that you need to specify an encoding and use the encode or decode methods of unicode or string ... Thanks! It works. Generally i write ' uunicode characters ', but in this case it was impossible. Moreover i forgot u in the next of my function: if item.text(0) == uFiltres Vidéos -- alteo_gange ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] identify a QTreeWidgetItem
Le mardi 23 octobre 2007, Jim Bublitz a écrit : On Tuesday 23 October 2007 02:13, alteo_gange wrote: Hi everybody! I have created several QTreeWidgetItem and connected a signal itemClicked(QTreeWidgetItem *,int) on the QTreeWidget. treeWidget=QtGui.QTreeWidget(widget) ... itemTree1=QtGui.QTreeWidgetItem(treeWidget) ... itemTree2=QtGui.QTreeWidgetItem(treeWidget) ... self.connect(treeWidget,QtCore.SIGNAL(itemClicked(QTreeWidgetItem *,int)),self.function) ... def function(self, item): print item 'print item' return: PyQt4.QtGui.QTreeWidgetItem object at 0x82cf62c. It's very abstract! I must identify QTreeWidgetItem in order to connect it an action (view a widget on the right), but how? With a method of the item reference? Which? I don't know. Store the items in a dict as you create them: self.itemDict = {} itemTree1=QtGui.QTreeWidgetItem(treeWidget) self.itemDict [itemTree1] = ?? # could be the associated widget that you want # to connect to, or a # string identifier itemTree2=QtGui.QTreeWidgetItem(treeWidget) self.itemDict [itemTree2] = ?? ... def function (self, item): widget = self.itemDict [item] ... Great! Now, my code is more secure. I can use several times the same text on several QTreeWidgetItem and i can rename QTreeWidgetItem text without problems (the function mustn't be change). Thanks! -- alteo_gange ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] identify a QTreeWidgetItem
Hi everybody! I have created several QTreeWidgetItem and connected a signal itemClicked(QTreeWidgetItem *,int) on the QTreeWidget.: treeWidget=QtGui.QTreeWidget(widget) ... itemTree1=QtGui.QTreeWidgetItem(treeWidget) ... itemTree2=QtGui.QTreeWidgetItem(treeWidget) ... self.connect(treeWidget,QtCore.SIGNAL(itemClicked(QTreeWidgetItem *,int)),self.function) ... def function(self, item): print item 'print item' return: PyQt4.QtGui.QTreeWidgetItem object at 0x82cf62c. It's very abstract! I must identify QTreeWidgetItem in order to connect it an action (view a widget on the right), but how? With a method of the item reference? Which? I don't know. -- alteo_gange ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] identify a QTreeWidgetItem
I'm sorry for the multiple messages. Few subscription problems. Now, it's OK. -- alteo_gange ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] identify a QTreeWidgetItem
On Tuesday 23 October 2007 02:13, alteo_gange wrote: Hi everybody! I have created several QTreeWidgetItem and connected a signal itemClicked(QTreeWidgetItem *,int) on the QTreeWidget. treeWidget=QtGui.QTreeWidget(widget) ... itemTree1=QtGui.QTreeWidgetItem(treeWidget) ... itemTree2=QtGui.QTreeWidgetItem(treeWidget) ... self.connect(treeWidget,QtCore.SIGNAL(itemClicked(QTreeWidgetItem *,int)),self.function) ... def function(self, item): print item 'print item' return: PyQt4.QtGui.QTreeWidgetItem object at 0x82cf62c. It's very abstract! I must identify QTreeWidgetItem in order to connect it an action (view a widget on the right), but how? With a method of the item reference? Which? I don't know. Store the items in a dict as you create them: self.itemDict = {} itemTree1=QtGui.QTreeWidgetItem(treeWidget) self.itemDict [itemTree1] = ?? # could be the associated widget that you want # to connect to, or a # string identifier itemTree2=QtGui.QTreeWidgetItem(treeWidget) self.itemDict [itemTree2] = ?? ... def function (self, item): widget = self.itemDict [item] ... Jim ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt