Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyItemDelegate: public QItemDelegate
- {
- public:
- MyItemDelegate(QObject* pParent = 0) : QItemDelegate(pParent)
- {
- }
- void paint(QPainter* pPainter, const QStyleOptionViewItem& rOption, const QModelIndex& rIndex) const
- {
- QStyleOptionViewItem ViewOption(rOption);
- QColor ItemForegroundColor = rIndex.data(Qt::ForegroundRole).value<QColor>();
- if (ItemForegroundColor.isValid())
- {
- if (ItemForegroundColor != rOption.palette.color(QPalette::WindowText))
- {
- ViewOption.palette.setColor(QPalette::HighlightedText, ItemForegroundColor);
- }
- }
- QItemDelegate::paint(pPainter, ViewOption, rIndex);
- }
- };
- QTableWidget* pTable = new QTableWidget(...);
- pTable->setItemDelegate(new MyItemDelegate(this));
- QVariant MySortFilterProxyModel::data(const QModelIndex & index, int role = Qt::DisplayRole) {
- // assuming error state and modelindex row match
- if (role==Qt::BackgroundRole)
- return Qt::red;
- }
- if (noError)
- {
- pTable->setStyleSheet("QTableView {selection-background-color: #000000; selection-color: #FFFFFF;}");
- }
- else
- {
- pTable->setStyleSheet("QTableView {selection-background-color: #FF0000; selection-color: #0000FF;}");
- }
Add Comment
Please, Sign In to add comment