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:
...
...
ProformaDelegate *spin_miktar;
spin_miktar = new ProformaDelegate(tableProformaindex);
...
QTableWidgetItem *prof_x_miktar = new QTableWidgetItem(Proformaindex.value(6).toString());
...
ProformaDelegate *spin_miktar;
spin_miktar = new ProformaDelegate(tableProformaindex);
To copy to clipboard, switch view to plain text mode
in the delegate (tableProformaindex):
editor->setMaximum(4000000000);
editor->setDecimals(2);
return editor;
...
{
ProformaDelegate
::ProformaDelegate(QObject *parent
){
}
...
double value = index.model()->data(index, Qt::DisplayRole).toDouble();
spinBox->setValue(value);
}
{
double value = spinBox->value();
model->setData(index, value, Qt::DisplayRole);
}
QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
editor->setMaximum(4000000000);
editor->setDecimals(2);
return editor;
...
void ProformaDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
ProformaDelegate::ProformaDelegate(QObject *parent)
: QItemDelegate(parent)
{
}
QWidget *ProformaDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
...
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
double value = index.model()->data(index, Qt::DisplayRole).toDouble();
spinBox->setValue(value);
}
void ProformaDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
double value = spinBox->value();
model->setData(index, value, Qt::DisplayRole);
}
To copy to clipboard, switch view to plain text mode
Bookmarks