20 #include <QApplication>
23 #include <QMouseEvent>
25 static QRect
CheckBoxRect(
const QStyleOptionViewItem &view_item_style_options) {
26 QStyleOptionButton check_box_style_option;
27 QRect check_box_rect = QApplication::style()->subElementRect(
28 QStyle::SE_CheckBoxIndicator,
29 &check_box_style_option);
30 QPoint check_box_point(view_item_style_options.rect.x() +
31 view_item_style_options.rect.width() / 2 -
32 check_box_rect.width() / 2,
33 view_item_style_options.rect.y() +
34 view_item_style_options.rect.height() / 2 -
35 check_box_rect.height() / 2);
36 return QRect(check_box_point, check_box_rect.size());
45 bool checkValue = index.data(Qt::DisplayRole).toBool();
47 QStyleOptionButton BtnStyle;
48 BtnStyle.state = QStyle::State_Enabled;
52 BtnStyle.state |= QStyle::State_On;
56 BtnStyle.state |= QStyle::State_Off;
59 BtnStyle.direction = QApplication::layoutDirection();
61 QApplication::style()->drawControl(QStyle::CE_CheckBox,&BtnStyle,painter );
65 const QModelIndex &index)
71 Qt::ItemFlags flags = model->flags(index);
72 if (!(flags & Qt::ItemIsEditable) || !(flags & Qt::ItemIsEnabled))
78 QMouseEvent* mouseEvent =
dynamic_cast<QMouseEvent*
>(event);
85 if (mouseEvent->type() != QEvent::MouseButtonRelease || mouseEvent->button() != Qt::LeftButton)
91 bool newState = !(index.data(Qt::EditRole).toBool());
93 return model->setData(index, QVariant(newState), Qt::EditRole);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
QmitkDoseVisualStyleDelegate(QObject *parent=0)
static QRect CheckBoxRect(const QStyleOptionViewItem &view_item_style_options)