Questions about models, items and views
-
wrote on 29 Oct 2020, 13:54 last edited by
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 -
-
wrote on 29 Oct 2020, 14:30 last edited by
What do you mean "by name"
I mean I want to be able to access item.File, item.Type, item.Score rather than only having access by an index into an array of QStrings
-
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
Davidwrote on 29 Oct 2020, 14:02 last edited by@Perdrix said in Questions about models, items and views:
the elements of each row by name
What do you mean "by name"?
Will a QTableView work to display the model?
Yes
-
-
wrote on 29 Oct 2020, 14:30 last edited by
What do you mean "by name"
I mean I want to be able to access item.File, item.Type, item.Score rather than only having access by an index into an array of QStrings
-
wrote on 29 Oct 2020, 14:46 last edited by VRonin
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"))
) -
wrote on 29 Oct 2020, 15:20 last edited by
OK! That will get the job done!
Thanks - it's not knowing the idioms that always catches you out.
1/5