I have a QtableView that displays a row of comboBoxes as the first row and additional rows that have a spinBoxDelegate (the spinBoxDelegate is actually a doubleSpinBox).
When I click on any cell (that is not in the first row) I get the delegate editor which I setup to show with 2 digits after the decimal point.
My row of comboBoxes allows switching between units of display (different units for each column depending on the data), so if I entered 2345 for the distance column when the appropriate comboBox was set to "m", the value will change to 2.345 when I change the comBox to show "km".
It all works fine and I'm able to switch between units and converting the values for the column that was changed but I still have one problem:
When I convert the values between the units, I set the new value in the cell through the model
for (int row=0; row<myModel->rowCount(); row++)
{
double value = myModel->data(myModel->index(row, col1)).toDouble();
convertedValue = convertValue( value );
myModel
->setData
(myModel
->index
(row, col1
),
QVariant(convertedValue
));
}
for (int row=0; row<myModel->rowCount(); row++)
{
double value = myModel->data(myModel->index(row, col1)).toDouble();
convertedValue = convertValue( value );
myModel->setData(myModel->index(row, col1), QVariant(convertedValue));
}
To copy to clipboard, switch view to plain text mode
The new value that is displayed in the cell is not limited to 2 digits after the decimal point and when I click to edit it the additional digits disappear and I'm left with 2 digits after the decimal point.
How can I set the converted data to show properly in the first place (with 2 digits after the decimal point)?
Bookmarks