I have a model containing in one column floats (ex: 22.7). Now, I want that in QTableView, it will be visualized together with the unit (MB): 22.7 MB. The reason I am doing so is because I want that sorting is based on floats, but the visualization is as I said with units.
I created a Model, a Filter and a View. But it does not work. Here is a piece of my code:
QStandardItemModel* model = new QStandardItemModel(this);
QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(0);
filterModel->setSourceModel(model);
QStandardItem* vSItem6 = new QStandardItem();
vSItem6->setData(22.7, Qt::DisplayRole);
model->setItem(1, 7, vSItem6);
QModelIndex index = model->index(1, 7, QModelIndex());
QString itext = model->data(index, Qt::DisplayRole).toString();
filterModel->setData(index, itext + " MB", Qt::DisplayRole);
mUi.tableView->setModel(filterModel);
mUi.tableView->setSortingEnabled(true);
mUi.tableView->show();
Everything seems to be fine, but in QTableView, only the float number is visualized (without the unit MB). Can anybody please help me? Thanks