I am having a QList as follow:
QList< QMap<QString, QString> > x;
for example:
table(1) <name<name(1),ABC> >
table(1) <age<age(1),10> >
I would like to have the "name" and "age" as columns header and down to them the values "ABC" and "10". Next when I have:
table(1) <name<name(2),DFG> >
table(1) <age<age(2),20> >
the values "DFG" and "20" comes in the next row
so, how can I do make this display ?
To do this, you have to pass your data to a model and then you can use QTableView to display your data; to set a model for a table use the following sample:
// creating a 4*4 table
QStandardItemModel* table_model = new QStandardItemModel(4, 4);
for (int row = 0; row < 4; ++row) {
for (int column = 0; column < 4; ++column) {
QStandardItem *item = new QStandardItem((QString())); // you should set your data here (in this case as a string)
table_model.setItem(row, column, item);
}
}
then you should pass the model to a tableview:
QTableView table;
table.setModel(table_model);
table.show();