{
QStyledItemDelegate::paint(painter, option, index);
if (!index.isValid() || index.column() != ButtonColumn) {
return;
}
State s = (State)(index.data(Qt::UserRole).toInt());
if (s == Hovered)
opt.
state |
= QStyle::State_MouseOver;
if (s == Pressed)
opt.
state |
= QStyle::State_Sunken;
opt.
state |
= QStyle::State_Enabled;
opt.rect = option.rect.adjusted(1, 1, -1, -1);
opt.text = trUtf8("Button text");
}
void MyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyledItemDelegate::paint(painter, option, index);
if (!index.isValid() || index.column() != ButtonColumn) {
return;
}
QStyleOptionButton opt;
State s = (State)(index.data(Qt::UserRole).toInt());
if (s == Hovered)
opt.state |= QStyle::State_MouseOver;
if (s == Pressed)
opt.state |= QStyle::State_Sunken;
opt.state |= QStyle::State_Enabled;
opt.rect = option.rect.adjusted(1, 1, -1, -1);
opt.text = trUtf8("Button text");
QApplication::style()->drawControl(QStyle::CE_PushButton, &opt, painter, 0);
}
To copy to clipboard, switch view to plain text mode
Bookmarks