-
Notifications
You must be signed in to change notification settings - Fork 1
/
customdelegate.cpp
45 lines (34 loc) · 1.2 KB
/
customdelegate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//#include <cfloat>
#include <QDoubleSpinBox>
#include "customdelegate.h"
CustomDelegate::CustomDelegate(QObject *parent) :
QItemDelegate(parent)
{
}
QWidget* CustomDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QDoubleSpinBox *dsb = new QDoubleSpinBox(parent);
dsb->setMinimum(-99999);
dsb->setMaximum(99999);
dsb->setButtonSymbols(QDoubleSpinBox::NoButtons);
dsb->setSingleStep(0);
dsb->setDecimals(3);
return dsb;
}
void CustomDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
double value = index.model()->data(index, Qt::EditRole).toDouble();
QDoubleSpinBox *dsb = static_cast<QDoubleSpinBox *>(editor);
dsb->setValue(value);
}
void CustomDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
QDoubleSpinBox *dsb = static_cast<QDoubleSpinBox *>(editor);
dsb->interpretText();
double value = dsb->value();
model->setData(index, value, Qt::EditRole);
}
void CustomDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
editor->setGeometry(option.rect);
}