
Originally Posted by
montylee
But using custom delegate i think the custom drawing will only be visible to the user when it goes into edit mode.
No, that's incorrect. Everything you see in the table is drawn by the delegate. Take a look at QTableView source code, there is no code related to rendering items.
Currently the normal checkbox is visible at all times, so i just want to add custom drawing to it. But i am not sure how to draw it as it's not a real checkbox.
It's not a real checkbox. It's drawn by the delegate. Here is the code it uses:
const QRect &rect, Qt
::CheckState state
) const {
if (!rect.isValid())
return;
opt.rect = rect;
opt.
state = opt.
state & ~
QStyle::State_HasFocus;
switch (state) {
case Qt::Unchecked:
opt.
state |
= QStyle::State_Off;
break;
case Qt::PartiallyChecked:
opt.
state |
= QStyle::State_NoChange;
break;
case Qt::Checked:
opt.
state |
= QStyle::State_On;
break;
}
const QWidget *widget
= d
->widget
(option
);
style
->drawPrimitive
(QStyle::PE_IndicatorViewItemCheck,
&opt, painter, widget
);
}
void QItemDelegate::drawCheck(QPainter *painter,
const QStyleOptionViewItem &option,
const QRect &rect, Qt::CheckState state) const
{
Q_D(const QItemDelegate);
if (!rect.isValid())
return;
QStyleOptionViewItem opt(option);
opt.rect = rect;
opt.state = opt.state & ~QStyle::State_HasFocus;
switch (state) {
case Qt::Unchecked:
opt.state |= QStyle::State_Off;
break;
case Qt::PartiallyChecked:
opt.state |= QStyle::State_NoChange;
break;
case Qt::Checked:
opt.state |= QStyle::State_On;
break;
}
const QWidget *widget = d->widget(option);
QStyle *style = widget ? widget->style() : QApplication::style();
style->drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &opt, painter, widget);
}
To copy to clipboard, switch view to plain text mode
Bookmarks