1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/SharerMax-VMS

Клонировать/Скачать
combodelegate.cpp 1.4 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
SharerMax Отправлено 07.11.2013 19:55 8a3891f
#include "combodelegate.h"
ComboDelegate::ComboDelegate(QObject *parent)
: QItemDelegate(parent)
{
}
QWidget *ComboDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
const QModelIndex &/* index */) const
{
QComboBox *editor = new QComboBox(parent);
editor->addItem("男");
editor->addItem("女");
editor->installEventFilter(const_cast<ComboDelegate*>(this));
return editor;
}
void ComboDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
QString str = index.model()->data(index).toString();
QComboBox *box = static_cast<QComboBox*>(editor); //staic_cast <type-id> (expression)
//该运算符把expression转换为type-id类型,但没有运行时类型检查来保证转换的安全性
int i = box->findText(str);
box->setCurrentIndex(i);
}
void ComboDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QComboBox *box = static_cast<QComboBox*>(editor);
QString str = box->currentText();
model->setData(index, str);
}
void ComboDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/SharerMax-VMS.git
git@api.gitlife.ru:oschina-mirror/SharerMax-VMS.git
oschina-mirror
SharerMax-VMS
SharerMax-VMS
master