void MyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{ if (option.state & QStyle::State_Selected) { if (index.column() != myColumn) { painter->fillRect(option.rect, QColor(0,0,255,255)); } else { painter->fillRect(option.rect, QColor(255,0,0,255)); } } QItemDelegate::paint(painter, option, index); }...QTableView *table = new QTableView();table->setSelectionBehavior(QAbstractItemView::SelectRows);QPalette palette;palette.setColor(QPalette::Normal, QPalette::Highlight, QColor(0,0,0,0));table->setPalette(palette);...
void MyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{ if (index.column() == myColumn && index.data( Qt::DisplayRole ).toString() != tr("Норма") ) { painter->fillRect(option.rect, QColor(255,0,0,255)); } QItemDelegate::paint(painter, option, index);}
void MyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{ if (index.column() == myColumn && index.data( Qt::DisplayRole ).toString() != tr("Норма") ) { option.palette.setBrush(QPalette::Text,Qt::red); } QItemDelegate::paint(painter, option, index);}
... option.palette.setBrush(QPalette::Text,Qt::red);...
if (index.column() == myColumn && index.data( Qt::DisplayRole ).toString() != tr("Норма") ) { QStyleOptionViewItem myOption = option; myOption .palette.setBrush(QPalette::Normal, QPalette::Text,Qt::red); QItemDelegate::paint(painter, myOption , index);} else { QItemDelegate::paint(painter, option, index);}