20 #include <QApplication>
22 #include <QPushButton>
23 #include <QColorDialog>
24 #include <QMouseEvent>
31 const QModelIndex &index)
const
33 QVariant data = index.data(Qt::EditRole);
35 if (data.canConvert<QColor>())
37 QColor color = data.value<QColor>();
39 painter->fillRect(option.rect, color);
43 QStyledItemDelegate::paint(painter, option, index);
48 const QModelIndex &index)
54 Qt::ItemFlags flags = model->flags(index);
55 if (!(flags & Qt::ItemIsEditable) || !(flags & Qt::ItemIsEnabled))
61 QMouseEvent* mouseEvent =
dynamic_cast<QMouseEvent*
>(event);
68 if (mouseEvent->type() != QEvent::MouseButtonRelease || mouseEvent->button() != Qt::LeftButton)
74 QColor oldcolor = index.data(Qt::EditRole).value<QColor>();
75 QColor newColor = QColorDialog::getColor(oldcolor, NULL);
77 if (newColor.isValid())
79 return model->setData(index, QVariant(newColor), Qt::EditRole);
QmitkDoseColorDelegate(QObject *parent=0)
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const