-
Notifications
You must be signed in to change notification settings - Fork 6
/
infoDelegate.cpp
55 lines (35 loc) · 1.02 KB
/
infoDelegate.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
#include "infoDelegate.h"
infoDelegate::infoDelegate(QObject *parent):QStyledItemDelegate(parent)
{
}
QWidget* infoDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (index.column() == 4)
{
QComboBox *sexBox = new QComboBox(parent);
sexBox->addItem("男");
sexBox->addItem("女");
return sexBox;
}
else
{
return QStyledItemDelegate::createEditor(parent, option, index);
}
}
void infoDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
QStyledItemDelegate::setEditorData(editor, index);
}
void infoDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
if (index.column() == 4)
{
QComboBox* sexEdit = qobject_cast<QComboBox*>(editor);
QString sex = sexEdit->currentText();
model->setData(index, sex);
}
else
{
QStyledItemDelegate::setModelData(editor, model, index);
}
}