Arend
25th November 2012, 22:56
Hello,
I want a tableView with doubles, for instance:
QVector<double> data(10);
for (int i=0;i<10;++i)
data[i]=1+i/10;
QStandardItemModel *model = new QStandardItemModel(10,2,this);
model->setHorizontalHeaderItem(0, new QStandardItem(QString("Column 1")));
...
for(int row=0;row<10;++row)
for(int col=0;col<2;++col)
{
QModelIndex index = model -> index(row,col,QModelIndex());
model->setData(index,data[row]);
}
But I get integers in the table, how can I get doubles: 1.1
Regards,
Arend
Added after 12 minutes:
I have solved this one
model->setData(index(row,column),QString::number(yourNumb er, 'f', 3));
I want a tableView with doubles, for instance:
QVector<double> data(10);
for (int i=0;i<10;++i)
data[i]=1+i/10;
QStandardItemModel *model = new QStandardItemModel(10,2,this);
model->setHorizontalHeaderItem(0, new QStandardItem(QString("Column 1")));
...
for(int row=0;row<10;++row)
for(int col=0;col<2;++col)
{
QModelIndex index = model -> index(row,col,QModelIndex());
model->setData(index,data[row]);
}
But I get integers in the table, how can I get doubles: 1.1
Regards,
Arend
Added after 12 minutes:
I have solved this one
model->setData(index(row,column),QString::number(yourNumb er, 'f', 3));