[SOLVED] Way to save integers in a model, compatible with QStyledItemDelegate?

Issue

I’m searching for a way to save integers and strings in a model and add new ones/ remove them. Maybe I will use QStyledItemDelegate soon too, so it needs to be a compatible solution.

I have some Integers and Strings in a Qsqltable. Next, I want to add a custom row (should only be added to my model, not to the database). As far as I know, QStandarditemmodel does only support Strings. The final goal is to show the data on a tableview or/and listview.

I tried to solve with QStandarditemmodel and setData() wich supports QVariant. But I guess the “data” is only for background information.

Solution

After some years of experience, I got the answer: QStandardItemmodel is the best solution for such a need.
I didn’t knew a lot about Roles back then, so I didn’t knew about DisplayRole, wich would have solved my problem.

Answered By – ratloser

Answer Checked By – Cary Denson (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *