[PyQt] qtreewidget only printing first character of my strings
Here's my code: selected = None self.treeWidget_iRulesList.clear() self.treeWidget_iRulesList.setColumnCount(1) self.treeWidget_iRulesList.setHeaderLabels([Rules]) self.treeWidget_iRulesList.setItemsExpandable(True) for item in allrules.keys(): #print item hdr = QTreeWidgetItem(item) self.treeWidget_iRulesList.addTopLevelItem(hdr) self.treeWidget_iRulesList.expandItem(hdr) for x in allrules[item]: #print x rule = QTreeWidgetItem(hdr, x) self.treeWidget_iRulesList.addTopLevelItem(rule) If I uncomment my print statements, each string is printed as expected, but in the QTreeWidget, I only get the first character: -g g t t -l h u _ And so on. Any ideas? Thanks in advance. Jason ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] qtreewidget only printing first character of my strings
On Donnerstag 21 April 2011, Jason Rahm wrote: If I uncomment my print statements, each string is printed as expected, but in the QTreeWidget, I only get the first character: I think QTreeWidgetItem expects a string list, not a string. Maybe [x] instead of x works better? -- Wolfgang ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] qtreewidget only printing first character of my strings
That's because the following constructor is being used when you call QTreeWidgetItem(hdr, x): * *QTreeWidgetItem ( QTreeWidgetItem * parent, const QStringList strings, int type = Type ) so it is treating your string as a list of strings. Since your column count is 1, you are only seeing the first character. You need to change your code as follows: QTreeWidgetItem(hdr, [x]) -Selim Jason Rahm wrote: Here's my code: selected = None self.treeWidget_iRulesList.clear() self.treeWidget_iRulesList.setColumnCount(1) self.treeWidget_iRulesList.setHeaderLabels([Rules]) self.treeWidget_iRulesList.setItemsExpandable(True) for item in allrules.keys(): #print item hdr = QTreeWidgetItem(item) self.treeWidget_iRulesList.addTopLevelItem(hdr) self.treeWidget_iRulesList.expandItem(hdr) for x in allrules[item]: #print x rule = QTreeWidgetItem(hdr, x) self.treeWidget_iRulesList.addTopLevelItem(rule) If I uncomment my print statements, each string is printed as expected, but in the QTreeWidget, I only get the first character: -g g t t -l h u _ And so on. Any ideas? Thanks in advance. Jason ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt attachment: Selim_Tuvi.vcf___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] qtreewidget only printing first character of my strings
Yes, that works much better. Thanks for the help. Jason -Original Message- From: Wolfgang Rohdewald [mailto:wolfg...@rohdewald.de] Sent: Thursday, April 21, 2011 11:29 AM To: pyqt@riverbankcomputing.com Cc: Jason Rahm Subject: Re: qtreewidget only printing first character of my strings On Donnerstag 21 April 2011, Jason Rahm wrote: If I uncomment my print statements, each string is printed as expected, but in the QTreeWidget, I only get the first character: I think QTreeWidgetItem expects a string list, not a string. Maybe [x] instead of x works better? -- Wolfgang ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt