-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLineEditDelegate.cpp
More file actions
45 lines (36 loc) · 1.29 KB
/
Copy pathLineEditDelegate.cpp
File metadata and controls
45 lines (36 loc) · 1.29 KB
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 <QLineEdit>
#include <QPainter>
#include "LineEditDelegate.h"
LineEditDelegate::LineEditDelegate(QObject *parent) :
QStyledItemDelegate(parent)// QItemDelegate(parent)
{
}
QWidget *LineEditDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
const QModelIndex &/* index */) const
{
QLineEdit *editor = new QLineEdit(parent);
QRegExp reg("[0-9A-Fa-f.x-]{1,16}");
QRegExpValidator* validator = new QRegExpValidator(reg, editor);
editor->setValidator(validator);
return editor;
}
void LineEditDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
QString val = index.model()->data(index, Qt::EditRole).toString();
QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
lineEdit->setText(val);
}
void LineEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
QString value = lineEdit->text();
model->setData(index, value, Qt::EditRole);
}
void LineEditDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}