QVariant data ( const QModelIndex & index, int role ) { ... if( role == Qt::BackgroundColorRole ) { QModelIndex controlIndex = index.sibling( index.row(), конкретная_колонка ); return ( controlIndex.data( Qt::DisplayRole ).toInt() == -1 ) ? QColor( Qt::red ) : QVariant(); } }
qTblVwSearchDocs->setSelectionMode(QAbstractItemView::ContiguousSelection); qTblVwSearchDocs->setSelectionBehavior(QAbstractItemView::SelectRows); connect(qTblVwSearchDocs, SIGNAL(doubleClick(QModelIndex)), this, SLOT(searchDocEnter(QModelIndex))); connect(qTblVwSearchDocs, SIGNAL(pressClick(QModelIndex)), this, SLOT(checkDoc(QModelIndex)));TableView::TableView(QWidget *parent) : QTableView(parent){}void TableView::mouseDoubleClickEvent ( QMouseEvent *event ){ emit(doubleClick(this->indexAt(QPoint(event->pos().x(), event->pos().y())))); this->selectRow(this->currentIndex().row()); event->accept();}void TableView::mousePressEvent(QMouseEvent *event ){ if(event->button() == Qt::RightButton) { event->accept(); return; } emit(pressClick(this->indexAt(QPoint(event->pos().x(), event->pos().y())))); event->accept();}
void TableView::mouseDoubleClickEvent ( QMouseEvent *event ){ emit(doubleClick(this->indexAt(QPoint(event->pos().x(), event->pos().y())))); this->selectRow(this->indexAt(QPoint(event->pos().x(), event->pos().y())).row()); event->accept();}void TableView::mousePressEvent(QMouseEvent *event ){ if(event->button() == Qt::RightButton) { event->accept(); return; } emit(pressClick(this->indexAt(QPoint(event->pos().x(), event->pos().y())))); this->selectRow(this->indexAt(QPoint(event->pos().x(), event->pos().y())).row()); event->accept();}