Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
List of Items with texts and icons. QAbstractItemModel?
dediggefedde last edited by
I'm pretty new to QT, so there might be some misunderstandings in concepts.
What I would like to display is a list (
ListView) of Items of which each displays multiple texts and icons.
I can successfully display single text elements with
QStandardItemModeland I read about subclassing
QAbstractItemModelif you need to display things differently. In QT help I also found an example for having a list of images (puzzle), but I couldn't find a combination or an example how to set the positions of multiple text elements.
In the past in vc++ or bcc I usually used the graphical base class (for labels etc.), subclassed it and changed the
mouse[...]events until it looked like I want.
To display a list of items that show multiple text and icons, would it be better to subclass
QAbstractItemModeland put it into a
Listviewor to create my own "Listview" as a
VRonin last edited by VRonin
The model does not determine how things are displayed, it just contains the data.
The view determines how the data as a whole is displayed (tree, list, table, etc.)
The delegate determines how individual items in the view are displayed.
check http://doc.qt.io/qt-5/model-view-programming.html for more detail
From your description it looks like what you need to subclass QStyledItemDelegate. What you need to do is store your text and icons in different Data Roles from Qt::UserRole onward and use the delegate paint method to retrieve them and display them.
The star delegate example is a good place to start
dediggefedde last edited by dediggefedde
Thanks for the fast and helpful reply!
I took a look into the model/view explanation and the star delegate example.
Edit: Sorry, I forgot to set the data to 0 on the QListView.
setItemparameters are (data,role), for QTableWidget it's (role,data)