C++ (Qt)QAbstractItemModel* m = table->model();m->setData( m->index( row, col ), QBrush( Qt::red ), Qt::BackgroundRole );
C++ (Qt)void QDbfReader::fullSearch(){ QAbstractItemModel* m = view->model(); for (int i=0; i < view->model()->rowCount(); ++i) { for (int j = 0; j < view->model()->columnCount();++j) { m->setData( m->index( i, j ), QBrush( Qt::red ), Qt::BackgroundRole ); } } view->setModel(m);}
reqModel->setTable("activationrequest"); reqModel->setSort(ui->reqView->horizontalHeader()->sortIndicatorSection(),ui->reqView->horizontalHeader()->sortIndicatorOrder()); reqModel->select(); requestsAllFilterModel->setSourceModel(reqModel); requestsAllFilterModel->setFilterKeyColumn(-1); ui->reqView->setModel(requestsAllFilterModel); QAbstractItemModel* m = ui->reqView->model(); if (!m->setData( m->index( 1, 1 ), QBrush( Qt::red ), Qt::BackgroundRole )){ qDebug ()<<"Background nod set"; }
QSqlTableModel *reqModel;
class MyItemDelegate : public QItemDelegate{ Q_OBJECTpublic: MyItemDelegate(QObject *parent=0): QItemDelegate(parent) { } void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;};void MyItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{ QStyleOptionViewItem o = option; if (index.column() == 0) o.font.setBold(true); QItemDelegate::paint(painter,o,index);}...tableView->setItemDelegate(new MyItemDelegate(tableView));илиsetItemDelegateForColumn() вроде тоже есть....