class NTableDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
};
NTableDelegate
::NTableDelegate(QObject *parent
) : QStyledItemDelegate
(parent
){
}
{
val->setBottom(0);
editor->setValidator(val);
return editor;
}
{
double value = index.model()->data(index,Qt::EditRole).toDouble();
QLineEdit* line
= static_cast<QLineEdit
*>
(editor
);
line
->setText
(QString().
setNum(value
));
}
{
QLineEdit* line
= static_cast<QLineEdit
*>
(editor
);
model->setData(index,value);
}
{
editor->setGeometry(option.rect);
}
class NTableDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
NTableDelegate(QObject* parent);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
NTableDelegate::NTableDelegate(QObject *parent) : QStyledItemDelegate(parent)
{
}
QWidget* NTableDelegate::createEditor(QWidget* parent,const QStyleOptionViewItem &option,const QModelIndex &index) const
{
QLineEdit* editor = new QLineEdit(parent);
QDoubleValidator* val = new QDoubleValidator(editor);
val->setBottom(0);
val->setNotation(QDoubleValidator::StandardNotation);
editor->setValidator(val);
return editor;
}
void NTableDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
double value = index.model()->data(index,Qt::EditRole).toDouble();
QLineEdit* line = static_cast<QLineEdit*>(editor);
line->setText(QString().setNum(value));
}
void NTableDelegate::setModelData(QWidget* editor,QAbstractItemModel* model,const QModelIndex &index) const
{
QLineEdit* line = static_cast<QLineEdit*>(editor);
QString value = line->text();
model->setData(index,value);
}
void NTableDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
editor->setGeometry(option.rect);
}
To copy to clipboard, switch view to plain text mode
Bookmarks