123456789101112131415161718192021222324252627282930313233343536373839 |
- #include "DataTableItemDelegate.h"
- #include <QComboBox>
- #include <QLineEdit>
- #include <QDebug>
- DataTableComboDelegate::DataTableComboDelegate(QObject *parent) : QStyledItemDelegate(parent) { }
- QWidget *DataTableComboDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & /* option */,
- const QModelIndex & /* index */) const
- {
- QComboBox *w = new QComboBox(parent);
- w->addItem("成本型");
- w->addItem("效益型");
- return w;
- }
- void DataTableComboDelegate::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 DataTableComboDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
- {
- QComboBox *spinBox = static_cast<QComboBox *>(editor);
- QString value = spinBox->currentText();
- model->setData(index, value, Qt::EditRole);
- }
- void DataTableComboDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
- const QModelIndex & /*index*/) const
- {
- editor->setGeometry(option.rect);
- }
|