QdoublespinxBox に問題があります
col2 のデリゲートとして Qdoublespinxbox を使用しています。
しかし、私が9999999999999999999999999999999のような大きな数字を持っているとき
彼は正しく表示できません、彼は私に 1e+19 を表示します
私はこれを使用しました
#include "customtableselldelegate.h"
#include <QDoubleSpinBox>
#include <QComboBox>
#include <QDebug>
#include <databasemananger.h>
#include <QLocale>
customTableSellDelegate::customTableSellDelegate(QObject *parent) :
QStyledItemDelegate(parent)
{
}
QWidget *customTableSellDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if(!index.isValid())
return QStyledItemDelegate::createEditor(parent,option,index);
int col= index.column();
if(col == 0)
{
DataBaseMananger dbMgr;
QSqlQueryModel *queryModel = new QSqlQueryModel(parent);
queryModel->setQuery("SELECT articleDesignation FROM articles");
QComboBox *comboboxEditor = new QComboBox(parent);
comboboxEditor->setModel(queryModel);
//comboboxEditor->setEditable(true);
return comboboxEditor;
}
else if(col ==1 || col ==2 || col ==3 || col == 5 || col == 6 || col == 7)
{
QDoubleSpinBox *doubleSpinBoxEditor = new QDoubleSpinBox(parent);
doubleSpinBoxEditor->setRange(-999999999999999.99,999999999999999999.99);
//doubleSpinBoxEditor->setSuffix(" D.A");
doubleSpinBoxEditor->setDecimals(2);
doubleSpinBoxEditor->setButtonSymbols(QDoubleSpinBox::PlusMinus);
doubleSpinBoxEditor->setFrame(false);
return doubleSpinBoxEditor;
}else{
return QStyledItemDelegate::createEditor(parent,option,index);
}
}
void customTableSellDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
if(!index.isValid())
return QStyledItemDelegate::setEditorData(editor,index);
int col= index.column();
if(col == 0)
{
QString data = index.model()->data(index,Qt::DisplayRole).toString();
QComboBox *comboboxEditor = qobject_cast<QComboBox*>(editor);
comboboxEditor->setItemText(comboboxEditor->currentIndex(),data);
}
else if(col ==1 || col ==2 || col ==3 || col == 5 || col == 6 || col == 7)
{
double data = index.model()->data(index,Qt::DisplayRole).toDouble();
QDoubleSpinBox *doubleSpinBoxEditor = qobject_cast<QDoubleSpinBox*>(editor);
doubleSpinBoxEditor->setValue(data);
}else{
QStyledItemDelegate::setEditorData(editor,index);
}
}
void customTableSellDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
if(!index.isValid())
return QStyledItemDelegate::setModelData(editor,model,index);
int col= index.column();
if(col == 0)
{
QComboBox *comboboxEditor = qobject_cast<QComboBox*>(editor);
model->setData(index,comboboxEditor->currentText(),Qt::EditRole);
emit unlockRow(index);
}
else if(col ==1 ||col ==2 || col ==3 || col == 5 || col == 6 || col == 7)
{
QDoubleSpinBox *doubleSpinBoxEditor = qobject_cast<QDoubleSpinBox*>(editor);
model->setData(index,doubleSpinBoxEditor->value(),Qt::EditRole);
if(col == 1 || col == 2)
{
emit qtyPriceDataChanged(index);
}
}else{
QStyledItemDelegate::setModelData(editor,model,index);}
}
void customTableSellDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
editor->setGeometry(option.rect);
}
void customTableSellDelegate::emitUnlockRow(QString str, QModelIndex index)
{
emit unlockRow(index);
}
#include "customtableselldelegate.h"
#include <QDoubleSpinBox>
#include <QComboBox>
#include <QDebug>
#include <databasemananger.h>
#include <QLocale>
customTableSellDelegate::customTableSellDelegate(QObject *parent) :
QStyledItemDelegate(parent)
{
}
QWidget *customTableSellDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if(!index.isValid())
return QStyledItemDelegate::createEditor(parent,option,index);
int col= index.column();
if(col == 0)
{
DataBaseMananger dbMgr;
QSqlQueryModel *queryModel = new QSqlQueryModel(parent);
queryModel->setQuery("SELECT articleDesignation FROM articles");
QComboBox *comboboxEditor = new QComboBox(parent);
comboboxEditor->setModel(queryModel);
//comboboxEditor->setEditable(true);
return comboboxEditor;
}
else if(col ==1 || col ==2 || col ==3 || col == 5 || col == 6 || col == 7)
{
QDoubleSpinBox *doubleSpinBoxEditor = new QDoubleSpinBox(parent);
doubleSpinBoxEditor->setRange(-999999999999999.99,999999999999999999.99);
//doubleSpinBoxEditor->setSuffix(" D.A");
doubleSpinBoxEditor->setDecimals(2);
doubleSpinBoxEditor->setButtonSymbols(QDoubleSpinBox::PlusMinus);
doubleSpinBoxEditor->setFrame(false);
return doubleSpinBoxEditor;
}else{
return QStyledItemDelegate::createEditor(parent,option,index);
}
}
void customTableSellDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
if(!index.isValid())
return QStyledItemDelegate::setEditorData(editor,index);
int col= index.column();
if(col == 0)
{
QString data = index.model()->data(index,Qt::DisplayRole).toString();
QComboBox *comboboxEditor = qobject_cast<QComboBox*>(editor);
comboboxEditor->setItemText(comboboxEditor->currentIndex(),data);
}
else if(col ==1 || col ==2 || col ==3 || col == 5 || col == 6 || col == 7)
{
double data = index.model()->data(index,Qt::DisplayRole).toDouble();
QDoubleSpinBox *doubleSpinBoxEditor = qobject_cast<QDoubleSpinBox*>(editor);
doubleSpinBoxEditor->setValue(data);
}else{
QStyledItemDelegate::setEditorData(editor,index);
}
}
void customTableSellDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
if(!index.isValid())
return QStyledItemDelegate::setModelData(editor,model,index);
int col= index.column();
if(col == 0)
{
QComboBox *comboboxEditor = qobject_cast<QComboBox*>(editor);
model->setData(index,comboboxEditor->currentText(),Qt::EditRole);
emit unlockRow(index);
}
else if(col ==1 ||col ==2 || col ==3 || col == 5 || col == 6 || col == 7)
{
QDoubleSpinBox *doubleSpinBoxEditor = qobject_cast<QDoubleSpinBox*>(editor);
model->setData(index,doubleSpinBoxEditor->value(),Qt::EditRole);
if(col == 1 || col == 2)
{
emit qtyPriceDataChanged(index);
}
}else{
QStyledItemDelegate::setModelData(editor,model,index);}
}
void customTableSellDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
editor->setGeometry(option.rect);
}
void customTableSellDelegate::emitUnlockRow(QString str, QModelIndex index)
{
emit unlockRow(index);
}
しかし、実際には何も違いはありません