#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;
|
|
QString curText = qvariant_cast<QString>(index.data());
|
|
vector<QString> vecq;
|
vecq.push_back("技术维护人员");
|
vecq.push_back("系统管理员");
|
vecq.push_back("安全管理人员");
|
vecq.push_back("普通采矿员工");
|
|
text << curText;
|
for(QString role : vecq){
|
if(curText!=role){
|
text << role;
|
}
|
}
|
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);
|
}
|