-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqcomboboxdelegate.cpp
34 lines (29 loc) · 1.09 KB
/
qcomboboxdelegate.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
#include "qcomboboxdelegate.h"
QComboBoxDelegate::QComboBoxDelegate(QStringList list,QObject * parent)
{
Q_UNUSED(parent);
strList = list;
}
QWidget *QComboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QComboBox * editor = new QComboBox(parent);
editor->setFrame(false);
editor->addItems(strList);
return editor;
}
void QComboBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
QString value = index.model()->data(index,Qt::EditRole).toString();
QComboBox * combobox = static_cast<QComboBox *>(editor);
combobox->setCurrentText(value);
}
void QComboBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
QComboBox * combobox = static_cast<QComboBox *>(editor);
QString value = combobox->currentText();
model->setData(index,value,Qt::EditRole);
}
void QComboBoxDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
editor->setGeometry(option.rect);
}