[PyQt] qtreewidget only printing first character of my strings

Selim Tuvi Selim.Tuvi at pdi.dreamworks.com
Thu Apr 21 17:36:39 BST 2011


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 list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110421/7ffe9926/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Selim_Tuvi.vcf
Type: text/x-vcard
Size: 375 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110421/7ffe9926/attachment.vcf>


More information about the PyQt mailing list