1. In a TableView I have doubleSpinbox delegate, like count or money. the value comes from dataBase like numeric(10,4) I mean for example a cell seems "100000.1200", and after delegating it returns like "100000.12" or "450.0000" returns "450", that because It seems less.

2. I need to show these cells (like in ms excel) like ###,###.## for example "12,452,231.24" and need to keep (also like excel) more digits. I mean the value "1.2445" must seems like "1.24" but when in calculation, it must have its original value.

here is my codes:
in the main:

Qt Code:
  1. ...
  2. QTableWidgetItem *prof_x_miktar = new QTableWidgetItem(Proformaindex.value(6).toString());
  3. ...
  4. ProformaDelegate *spin_miktar;
  5. spin_miktar = new ProformaDelegate(tableProformaindex);
To copy to clipboard, switch view to plain text mode 

in the delegate (tableProformaindex):

Qt Code:
  1. QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
  2. editor->setMaximum(4000000000);
  3. editor->setDecimals(2);
  4. return editor;
  5. ...
  6.  
  7. void ProformaDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
  8. {
  9. ProformaDelegate::ProformaDelegate(QObject *parent)
  10. : QItemDelegate(parent)
  11. {
  12.  
  13. }
  14.  
  15. QWidget *ProformaDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
  16. ...
  17. QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
  18. double value = index.model()->data(index, Qt::DisplayRole).toDouble();
  19. spinBox->setValue(value);
  20. }
  21.  
  22. void ProformaDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
  23. {
  24. QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
  25. double value = spinBox->value();
  26. model->setData(index, value, Qt::DisplayRole);
  27. }
To copy to clipboard, switch view to plain text mode