Hi,

I am constructing a table on and listing prices in a column; I want to be able to sort the column based on the number in the cell (not text).

I was using the following code to fill the cells and it was working fine for numbers up to 999,999

Qt Code:
  1. auto widgetItemAmount = new QTableWidgetItem;
  2. widgetItemAmount ->setData(Qt::EditRole,query.value(8).toDouble());
  3. ui->ordersTableWidget->setItem(i,6,widgetItemAmount);
To copy to clipboard, switch view to plain text mode 

Once the content of the cell is over 1,000,000; it is populated in scientific notation (for ex. 3,500,000 is shown as 3.5e06)
I can avoid it by using the following code:

Qt Code:
  1. auto widgetItemAmount = new QTableWidgetItem;
  2. widgetItemAmount->setData(Qt::DisplayRole,QString::number(query.value(8).toDouble(),'f', 2));
  3. ui->ordersTableWidget->setItem(i,6,widgetItemAmount);
To copy to clipboard, switch view to plain text mode 

However, in this case the rows sort as the contents are text (not surprisingly since they are text).

Do you have any suggestions on how I can display the value in decimal format and sort the table numerically at the same time?

Thank you for your help in advance.