我在TableView的某列中添加了一个按钮, 请问在重绘的时候怎么改变这个按钮的样式,比如文字颜色, 设置鼠标经过时显示手势???
void ButtonDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (index.column() == 2)
{
//palette.setColor(QPalette::Text, Qt::blue);
QStyleOptionButton sBtn;
QRect r = option.rect;
int x,y,w,h;
w = 60;//button width
h = 30;//button height
x=r.x()+r.width()/2-w/2;
y=r.y()+r.height()/2-h/2;
sBtn.rect = QRect(x,y,w,h);
sBtn.text = QStringLiteral("点击使用");
sBtn.state = QStyle::State_Enabled;
QApplication::style()->drawControl(QStyle::CE_PushButtonLabel, &sBtn, painter);
}
}
void ButtonDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (index.column() == 2)
{
//palette.setColor(QPalette::Text, Qt::blue);
QStyleOptionButton sBtn;
QRect r = option.rect;
int x,y,w,h;
w = 60;//button width
h = 30;//button height
x=r.x()+r.width()/2-w/2;
y=r.y()+r.height()/2-h/2;
sBtn.rect = QRect(x,y,w,h);
sBtn.text = QStringLiteral("点击使用");
sBtn.state = QStyle::State_Enabled;
QApplication::style()->drawControl(QStyle::CE_PushButtonLabel, &sBtn, painter);
}
}