16,173
社区成员
发帖
与我相关
我的任务
分享
void ChooseWatchObjectDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QStyleOptionButton btn;
btn.rect = option.rect;
bool fg = index.model()->data(index).toBool();
if(fg == true)
{
btn.palette.setBrush(QPalette::Button,QBrush(QColor(Qt::green)));//无效
btn.text = tr("启动");
}
else
{
btn.palette.setBrush(QPalette::Background,QBrush(QColor(Qt::red)));//同样无效
btn.text = tr("停止");
}
btn.state |= QStyle::State_Enabled;
if(option.widget != NULL)
QApplication::style()->drawControl(QStyle::CE_PushButton,&btn,painter);
else
option.widget->style();
}
painter->setBrush(QBrush(QColor(Qt::red)));