QTableView, sqlite, wrong data type
I have a problem with QTableView not showing fractional part of a floating point number retrieved from sqlite query (i.e. QSqlQueryModel).
I've tested it with QSqlQuery - q.value(0).toDouble() returns correct floating point value. Yet QTableView shows only integer part.
How can I change QTableView or QSqlQueryModel column type?
edit: Here is sample code. Requires tableView object on MainWindow.
Code:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
db.setDatabaseName(":memory:");
db.open();
q.exec("create table t (col1)");
q.exec("insert into t (col1) values (161726.36)");
m->setQuery("select col1 from t");
ui->tableView->setModel(m);
}
Re: QTableView, sqlite, wrong data type
The default delegate handles the display of the DisplayRole of the model. For doubles:
Code:
text = locale.toString(value.toReal());
break;
The default formatting for QLocale::toString() with a double argument is 6 significant digits (not digits after the decimal point, see QString::number() argument formats). You want to provide your own delegate subclass that overrides displayText() or customise the model to return a formatted string in the DisplayRole (still return a Double in EditRole).