{
if (index.column() == 3) {
QVariant state
= index.
model()->data
(index, Qt
::CheckStateRole);
if (state == Qt::Checked) {
// Calculate rectangle to draw the checkbox icon
QRect rect
= option.
rect.
adjusted(20,
5,
-25,
-10);
if (option.
state & QStyle::State_Selected) { // Fill the highlight rectangle
painter->fillRect(option.rect, option.palette.highlight());
// Draw "ALL" icon in the first row and checkbox icons in other rows
if (index.row() == 0)
painter
->drawPixmap
(option.
rect,
QPixmap("all-on.png"));
else
painter
->drawPixmap
(rect,
QPixmap("check-icon-hl.png"));
} else {
if (index.row() == 0)
painter
->drawPixmap
(option.
rect,
QPixmap("all-on.png"));
else
painter
->drawPixmap
(rect,
QPixmap("check-icon.png"));
}
} else {
if (option.
state & QStyle::State_Selected) painter->fillRect(option.rect, option.palette.highlight());
if (index.row() == 0)
painter
->drawPixmap
(option.
rect,
QPixmap("all-off.png"));
}
} else {
QStyledItemDelegate::paint(painter, option, index);
}
}
void CheckboxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (index.column() == 3) {
QVariant state = index.model()->data(index, Qt::CheckStateRole);
if (state == Qt::Checked) {
// Calculate rectangle to draw the checkbox icon
QRect rect = option.rect.adjusted(20, 5, -25, -10);
if (option.state & QStyle::State_Selected) {
// Fill the highlight rectangle
painter->fillRect(option.rect, option.palette.highlight());
// Draw "ALL" icon in the first row and checkbox icons in other rows
if (index.row() == 0)
painter->drawPixmap(option.rect, QPixmap("all-on.png"));
else
painter->drawPixmap(rect, QPixmap("check-icon-hl.png"));
} else {
if (index.row() == 0)
painter->drawPixmap(option.rect, QPixmap("all-on.png"));
else
painter->drawPixmap(rect, QPixmap("check-icon.png"));
}
} else {
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.highlight());
if (index.row() == 0)
painter->drawPixmap(option.rect, QPixmap("all-off.png"));
}
} else {
QStyledItemDelegate::paint(painter, option, index);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks