Python Forum
[PyQt] QStandardItemModel; columns, icons
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] QStandardItemModel; columns, icons
#1
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.
Reply
#2
I think QStandardItem(icon, str) means column 0 -> icon, column 1 -> string
Reply
#3
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".
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Problems - buttons w icons not scrolling kraco 11 4,810 May-11-2020, 11:20 AM
Last Post: kraco
  Menus and icons changed after upgrade blackclover 0 1,939 May-11-2018, 08:14 PM
Last Post: blackclover

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020