QTableView: changing precision for double values
If a double is returned as an EditRole by the model, then (presumably) the QDoubleSpinBox is used by the QTableView as the editor. How can I change the precision in this control?
I haven't been able to find a good way to get to these spin boxes. The default delegate for QTableView
is QStyledItemDelegate . When you create an item in, Qt::EditRole
it uses items created by the standard QItemEditorFactory class , which you can access using QItemEditorFactory::defaultFactory()
. Then you could register your own editor, but I don't see a good way to edit the ones that already exist.
Instead, you should most likely implement your own delegate with some precision. There is an example to make a delegate using QSpinBox
which you replace with QDoubleSpinBox
. Then in createEditor
you then use setDecimals
to set the spin box to the precision you want. Then you apply this delegate to your table using setItemDelegate
.
According to the documentation, the accuracy QDoubleSpinBox
can be changed by calling decimals
.