wumu
2024-05-09 9ddb25babb774f773b62106fb4d1a9404af71fd9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "comboboxdelegate.h"
 
ComboBoxDelegate::ComboBoxDelegate(QStringList labels,QObject *parent)
    :QItemDelegate(parent),
      m_labels(labels)
{
 
}
 
QWidget *ComboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QComboBox *cbb = new QComboBox(parent);
    for(int i=0;i<m_labels.size();++i){
        cbb->addItem(m_labels.at(i));
    }
    return cbb;
}
 
void ComboBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
    QString val = ((QComboBox*)editor)->currentText();
    model->setData(index,val);
}