0
我有QdoublespinxBox爲什麼QdoublespixBox不能顯示大的數字正確
問題我使用Qdoublespinxbox在COL2代表,
,但是當我有大numbes像99999999999999999999999999999999
他不能正確顯示,他給我看了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);
}
但確實沒有什麼使得QDoubleSpinBox::textFromValue(double)
一個不同勢
我使用自定義委託,真的我不知道如何編碼 – advseo32
@ advseo32:顯示您的代碼 - 編輯問題。自定義代表什麼? QML視圖?基於QWidget的視圖? –
我使用簡單的qt程序的自定義代理 – advseo32