Python Forum

Full Version: QStandardItemModel; columns, icons
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am struggling to figure out something. I have a QTreeView fed by a QStandardItemModel; tree populates; multiple columns; great! Works. But, I am trying to plan out how to make the actual tree have icons for each node, while the other columns remain just strings. This is a flow of how I populate the model:
...
root = model.invisibleRootItem()
data = [data, data, data]
root.appendRow(data)
That code is the gist. I know that QStandardItem's support initializing with icons. Cool. So, QStandardItem(icon, str). But, wouldn't that mean all three items in the passed list (so, all three columns) have an icon? I don't want that. How can I make it so just the first element in data have an icon, but not the other two?

I posted this as a feeler. I'm about to continue making love to my IDE, but I'm not sure where to begin. The PyQt docs are what they are. I hope I'm making sense.
I think QStandardItem(icon, str) means column 0 -> icon, column 1 -> string
Something like that. I've worked with an QTreeWidget in the past and you may be right. But, the view has multiple columns, and maybe with that understanding view column 1 would have two columns per node, but I just don't want that to be passed to the remaining view columns. I just have to roll up my sleeves and test. I just hoped I could get a "do this".
Much ado for nothing, @Axel_Erfurt. One function and no refactoring, and all works as intended. I just don't know what Qt does, so wasn't sure how this would work. My question stands, 'cause I don't know why it works fine, but it does.