[Solved] Help using QStandardItemModel
-
Hi, I have the following code, taken from SpinBoxDelegate Example, but in my example, the QTableView does not shown the data. Any clue?
Best regards.
David
@
mdiMain = new QMdiArea;
mdiMain->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
mdiMain->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setCentralWidget(mdiMain);QMdiSubWindow *sub = new QMdiSubWindow;
QTableView *table = new QTableView;
QStandardItemModel model(4, 2);
for (int row = 0; row < 4; ++row)
for (int column = 0; column < 2; ++column)
model.setData(model.index(row, column, QModelIndex()), QVariant((row+1) * (column+1)));
table->setModel(&model);
sub->setWidget(table);
sub->show();
@ -
Hi stima_ua, thanks for your replay, but it did not work.
-
Hi Scylla, thanks for your replay.
What do you mean how long is my model alive?
I have noticed that in my example, when I refresh the model contents by filling it, the QTableView seems to be filled but just for about a second.
-
Great!!! Scylla.
You hit it, :-) in my example model has to be declared in the same place mdiMain was decladed.
I really appreciate your help and stima_ua, thanks for your help too.
@
mdiMain = new QMdiArea;
mdiMain->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
mdiMain->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setCentralWidget(mdiMain);QMdiSubWindow *sub = new QMdiSubWindow;
QTableView *table = new QTableView;
model = new QStandardItemModel(4, 2);
for (int row = 0; row < 4; ++row)
for (int column = 0; column < 2; ++column)
model.setData(model.index(row, column, QModelIndex()), QVariant((row+1) * (column+1)));
table->setModel(&model);
sub->setWidget(table);
sub->show();
@ -
Now, can I add a QIcon to the vertical o horizontal headers like in QTableWidget? I mean, can I do something like this with QTableView?
@
result->setHorizontalHeaderItem(row, new QTableWidgetItem(QIcon(":/MyIcon.png"), "Header"));
@