This is the original code :
int main(int argc, char *argv[])
{
tableView.setModel(&model);
tableView.horizontalHeader()->setStretchLastSection(true);
for (int row = 0; row < 4; ++row) {
for (int column = 0; column < 2; ++column) {
model.
setData(index,
QVariant((row
+1) * (column
+1)));
}
}
tableView.
setWindowTitle(QObject::tr("Spin Box Delegate"));
tableView.show();
return app.exec();
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QStandardItemModel model(4, 2);
QTableView tableView;
tableView.setModel(&model);
tableView.horizontalHeader()->setStretchLastSection(true);
for (int row = 0; row < 4; ++row) {
for (int column = 0; column < 2; ++column) {
QModelIndex index = model.index(row, column, QModelIndex());
model.setData(index, QVariant((row+1) * (column+1)));
}
}
tableView.setWindowTitle(QObject::tr("Spin Box Delegate"));
tableView.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
And this is my code (I use a TableView out on a window using Designer)
ui->tableView->setModel(&modelo);
ui->tableView->horizontalHeader()->setStretchLastSection(true);
for (int row = 0; row < 4; ++row) {
for (int column = 0; column < 2; ++column) {
modelo.
setData(index,
QVariant((row
+1) * (column
+1)));
}
}
QStandardItemModel modelo(4, 2);
ui->tableView->setModel(&modelo);
ui->tableView->horizontalHeader()->setStretchLastSection(true);
for (int row = 0; row < 4; ++row) {
for (int column = 0; column < 2; ++column) {
QModelIndex index = modelo.index(row, column, QModelIndex());
modelo.setData(index, QVariant((row+1) * (column+1)));
}
}
To copy to clipboard, switch view to plain text mode
(I only delete the 'delegate' code, in order to simply test how it works)
Ok, in my case I see the table but i dont see the cells neither its content.
What happens ?
Bookmarks