{
PropertyItem * item = (PropertyItem *)(index.internalPointer());
if(item)
{
switch(item->GetPropertyType())
{
...
case PropertyItem::PropertyTypeColor:
connect(((QPushButton *)editor
),
SIGNAL(clicked
()),
this,
SLOT(colorTypeClicked
()));
return editor;
break;
default:
return QStyledItemDelegate::createEditor(parent,option,index);
}
}
return QStyledItemDelegate::createEditor(parent,option,index);
}
{
PropertyItem * item = static_cast<PropertyItem*>(index.internalPointer());
if(item)
{
switch(item->GetPropertyType())
{
...
case PropertyItem::PropertyTypeColor:
currentValue = item->GetValue();
break;
default: QStyledItemDelegate::setEditorData(editor,index);
}
}
}
void PropertyDelegate::colorTypeClicked()
{
QWidget * editor
= qobject_cast<QWidget
*>
(sender
());
QColor current
= currentValue.
value<QColor>
();
currentValue
= QColorDialog::getColor(current,
NULL,tr
("Select color"));
editor->setFocus();
emit commitData(editor);
emit closeEditor(editor); // crashed here
}
QWidget *PropertyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
PropertyItem * item = (PropertyItem *)(index.internalPointer());
if(item)
{
QWidget * editor;
switch(item->GetPropertyType())
{
...
case PropertyItem::PropertyTypeColor:
editor = new QPushButton(parent);
((QPushButton *)editor)->setText("...");
connect(((QPushButton *)editor),SIGNAL(clicked()),this,SLOT(colorTypeClicked()));
return editor;
break;
default:
return QStyledItemDelegate::createEditor(parent,option,index);
}
}
return QStyledItemDelegate::createEditor(parent,option,index);
}
void PropertyDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
PropertyItem * item = static_cast<PropertyItem*>(index.internalPointer());
if(item)
{
switch(item->GetPropertyType())
{
...
case PropertyItem::PropertyTypeColor:
currentValue = item->GetValue();
break;
default: QStyledItemDelegate::setEditorData(editor,index);
}
}
}
void PropertyDelegate::colorTypeClicked()
{
QWidget * editor = qobject_cast<QWidget *>(sender());
QColor current = currentValue.value<QColor>();
currentValue = QColorDialog::getColor(current,NULL,tr("Select color"));
editor->setFocus();
emit commitData(editor);
emit closeEditor(editor); // crashed here
}
To copy to clipboard, switch view to plain text mode
Bookmarks