c++qtqabstractlistmodel

How to customize the display of a QListView


I have implemented a list of users in my Qt program, using the model/view principle of Qt. My QListView displays a subclass of QAbstractListModel and so far this works just fine.

Now I would like to customize the display of my user list (display the name on several line, add IP information, and so on: not really relevant, I just want something really custom).

I couldn't find anything in the Qt documentation regarding this: what are my options ?

Note: The items in the list do not need to (can't) be modified, if this can help.

Thank you.


Solution

  • You need to create a new item delegate class to handle the painting. Here is a good answer to a similar question.