我对 QdoublespinxBox 有疑问
我在 col2 中使用 Qdoublespinxbox 作为代表,
但是当我有像 999999999999999999999999999999999 这样的大数字时
他无法正确显示,他向我显示 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);
}
但真的没有什么不同