bool AmdinWidgetSqlModel::setData(const QModelIndex &index, const QVariant &value, int role){ QModelIndex primaryKeyIndex = QSqlQueryModel::index(index.row(), 1); int id = data(primaryKeyIndex,0).toInt(); clear(); bool ok; switch ( index.column() ) { case 1: { ok = setDate(id,value.toString()); break; } case 3: { ok = setTimeStart(id,value.toString()); break; } case 4: { ok = setCoordinatesStart(id,value.toString()); break; } case 5: { ok = setTimeStop(id,value.toString()); break; } case 6: { ok=setCoordinatesStop(id,value.toString()); break; } case 7: { ok=setTipe1(id,value.toFloat()); break; } case 8: { ok=setTipeOut1(id,value.toFloat()); break; } case 9: { ok=setTipe2(id,value.toFloat()); break; } case 10: { ok=setTipeFishOut2(id,value.toFloat()); break; } case 11: { ok=setTipeFish3(id,value.toFloat()); break; } case 12: { ok=setTipeOut3(id,value.toFloat()); break; } case 13: { ok=setTipe4(id,value.toFloat()); break; } case 14: { ok=setTipeOut4(id,value.toFloat()); break; } case 15: { ok=setTipe5(id,value.toFloat()); break; } case 16: { ok=setTipeOut5(id,value.toFloat()); break; } case 17: { ok=setTipe6(id,value.toFloat()); break; } case 18: { ok=setTipeOut6(id,value.toFloat()); break; } } refresh(); return ok;}
.............................. refresh(); emit dataChanged(index,index); return ok;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole ) const;
QVariant FisheryWidgetSqlModel::data(const QModelIndex &index, int role) const{ switch (role) { case Qt::BackgroundRole: if(index.column()==19) return Qt::darkGreen; // пусть такой для примера. break; } return QVariant();}
QVariant AmdinWidgetSqlModel::data(const QModelIndex &index, int role) const{ switch (role) { case Qt::BackgroundRole: if(index.column()==19) return Qt::darkGreen; // color for QBrush break; } switch ( index.column() ) //поменять тут { case 4: { // и тут выводим значение по индексу? } } return QVariant();}
C++ (Qt)QVariant AmdinWidgetSqlModel::data(const QModelIndex &index, int role) const{ if( role == Qt::BackgroundRole && index.column()==19 ) return Qt::darkGreen; // color for QBrush return QSqlQueryModel::data( index, role );}