11 #include <QApplication> 16 const bool reverse = (option.direction == Qt::RightToLeft);
17 const int width = (option.rect.height() * 2) / 3;
21 QStyleOptionViewItemV4 opt = option;
23 opt.rect.adjust(width,0,0,0);
25 opt.rect.adjust(0,0,-width,0);
27 if (!(index.model()->flags(index) & Qt::ItemIsEnabled))
29 opt.showDecorationSelected =
true;
30 opt.state |= QStyle::State_Selected;
34 QStyledItemDelegate::paint(painter, opt, index);
38 opt.rect = QRect(option.rect.x(), option.rect.y(),
39 width, option.rect.height());
41 opt.rect = QRect(option.rect.x() + option.rect.width() - width, option.rect.y(),
42 width, option.rect.height());
45 if (index.model()->hasChildren(index))
47 const QWidget *view = opt.widget;
49 QStyle *style = view ? view->style() : qApp->style();
50 style->drawPrimitive(QStyle::PE_IndicatorColumnViewArrow, &opt,
57 const QModelIndex &index)
59 QStandardItemModel *it =
dynamic_cast<QStandardItemModel*
>(model);
61 return QStyledItemDelegate::editorEvent(evt, model, option, index);
63 const QStandardItem *
item = it->itemFromIndex(index);
65 return QStyledItemDelegate::editorEvent(evt, model, option, index);
67 const Qt::CheckState before = item->checkState();
69 const bool rc = QStyledItemDelegate::editorEvent(evt, model, option, index);
71 const Qt::CheckState after = item->checkState();
74 QApplication::sendEvent(it->parent(),
new CheckBoxEvent(*item));
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
bool editorEvent(QEvent *evt, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
An event posted by the CheckBoxDelegate if the CheckBox is used.