-
Notifications
You must be signed in to change notification settings - Fork 0
/
g.cpp
65 lines (57 loc) · 1.72 KB
/
g.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "g.h"
/*
//=======================================================
// delegates
//==============
SpinBoxDelegate::SpinBoxDelegate(QObject *parent)
: QStyledItemDelegate(parent){
}
//
QWidget *SpinBoxDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &lso,
const QModelIndex &index) const{
sp("ce");
if (index.column()==2) {
QSpinBox *editor = new QSpinBox(parent);
editor->setFrame(false);
editor->setMinimum(0);
editor->setMaximum(100);
return editor;
} else {
return QStyledItemDelegate::createEditor(parent,lso,index);
}
}
//
void SpinBoxDelegate::setEditorData(QWidget *editor,const QModelIndex &index) const{
sp("sed");
if (index.column()==2) {
int value = index.model()->data(index, Qt::EditRole).toInt();
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
spinBox->setValue(value);
} else {
QStyledItemDelegate::setEditorData(editor,index);
}
}
//
void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const{
sp("smd");
if (index.column()==2) {
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
spinBox->interpretText();
int value = spinBox->value();
model->setData(index, value, Qt::EditRole);
} else {
QStyledItemDelegate::setModelData(editor,model,index);
}
}
//
void SpinBoxDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &) const{
sp("ueg");
editor->setGeometry(option.rect);
}
void SpinBoxDelegate::keyPressEvent(QKeyEvent* event){
QStyledItemDelegate::keyPressEvent(event);
}
*/