#include "qcomboxdelegate.h"
|
|
|
|
QComBoxDelegate::QComBoxDelegate()
|
{
|
|
}
|
|
QComBoxDelegate::QComBoxDelegate(QObject *p):QItemDelegate(p)
|
{
|
|
}
|
|
QWidget *QComBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
{
|
QComboBox * box = new QComboBox(parent);
|
QStringList text;
|
text << "普通采矿员工" << "技术维护人员" << "系统管理员"<< "安全管理人员";
|
box->addItems(text);
|
|
return box;
|
}
|
|
void QComBoxDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
{
|
QRect rec = option.rect;
|
editor->setGeometry(rec);
|
}
|
|
void QComBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
{
|
|
}
|
|
void QComBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
{
|
QString val = static_cast<QComboBox *>(editor)->currentText();
|
model->setData(index,val);
|
}
|