#include "delegate.h" propertyItemDelegate::propertyItemDelegate(QObject *parent): QItemDelegate(parent) { m_testList << "Sunday" << "Monday" << "tuesday" << "wednesday" << "friday" << "satday"; } QWidget *propertyItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem& option, const QModelIndex & index ) const { QWidget* l_editor = new checkStateComboBox(); l_editor->setParent(parent); return l_editor; } void propertyItemDelegate::setEditorData(QWidget *f_widget, const QModelIndex &index) const { QStringList l_itemsData = m_testList; //get the list you want to show; QStringList l_modelData = index.model()->data(index, Qt::DisplayRole).toString().split(";"); //existing data, I am showing only checked items data in editor //this logic is to check items which are previously checked based on data I am showing in editor //I get the data which I am showing in editor & I know those are the only items I checked checkStateComboBox* l_multiValuedWidget = static_cast(f_widget); foreach(QString l_itemData, l_itemsData) { bool l_checkState = l_modelData.contains(l_itemData); Qt::CheckState l_state = l_checkState ? Qt::Checked : Qt::Unchecked; l_multiValuedWidget->addItem(l_itemData, l_state); } } void propertyItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { QString l_data = QString::null; checkStateComboBox* l_multiValuedWidget = static_cast(editor); int size = l_multiValuedWidget->getItems().count(); for(int i=0; i < size; i++) { const QStandardItem* l_item = l_multiValuedWidget->getItem(i); //data of checked items only if(l_item && (Qt::Checked == l_item->checkState())) { QString l_itemData = l_item->data(Qt::DisplayRole).toString(); ((size-1) == i) ? (l_data = l_data + l_itemData) : (l_data = l_data + l_itemData + ";"); } } model->setData(index, l_data, Qt::EditRole); } void propertyItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex & /*index*/ ) const { QRect l_rect = option.rect; l_rect.adjust(0,0,0,l_rect.height()*0.3); editor->setGeometry(l_rect); }