How can I get rich text to QListView items in PyQt5 (QItemDelegate?)

223 Views Asked by At

I'm creating a personnel management software for my own use and basically I'd want to get my QListView to be prettier and more informative than by using QStandardItemModel and QStandardItem.

Essentially I'd like for the list to look something like this:

  Mr Smith sick
  Mrs Smith working
  Mr Anderson traveling
  Ms White working

Preferably also with an option of colors, but I couldn't find a quick tutorial for this.

I've understood that this could be accomplished by using QItemDelegate, but I tried to look at the documentation and it made my brain hurt. Could somebody inform how could I add rich-formatted text items to a QListView or point to a "for dummies" -tutorial? Thanks!

1

There are 1 best solutions below

1
Joonas Joensuu On

For my needs the answer was rather simple (as it usually is). Instead of using QListView directly, I used QListWidget, where I added a QListWidgetItem and to that I added my custom QWidget, where I could set fixed size constraints in a quick and simple manner thus eliminating the need to build custom models and delegates

With QLabel I can use rich text without problems.

Ie. what I asked for was not exactly what I needed. Yes, this is possibly not as an efficient solution as it could be, but for my needs it's more than sufficient.