Questions about models, items and views
-
I want to display some data that is tabular in form. There is no hierarchy. The model can be the data store
I want to have a check box and Icon in the first column of the data, and I want to be able to set attributes of a row by their name rather than by index. QStandardItemModel and QStandardItem appear to do a lot of what I want (as I am sure they are intended to):
-
Can I use QStandardItemModel/QStandardItem in a way that allows me to access the elements of each row by name, if so how can I do that?
-
If not is there a model that I can readily subclass that will allow access by column name and also allows use of an Icon and check box. If so how should I proceed to do that? Assume that the underlying data will be a structure/class of QStrings, or possible QStrings and integers. Say for the sake of argument that it has three members of type QString called File, Type and Score.
-
Will a QTableView work to display the model? The final display should look like:
Thanks
David -
-
what you normally do is set an enumerator to determine the columns:
enum ModelColumns{ mcFile , mcType , mcScore };
then you use
model->item(row,mcFile)
to access it usingQStandardItemModel
(or generically, to read/writemodel->index(row,mcFile).data()
/model->setData(model->index(row,mcFile),QStringLiteral("Something"))
)