void SpinBoxDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QString text = index.model()->data(index, Qt::DisplayRole).toString(); QRect rect = option.rect; QLinearGradient gradient(0,0, rect.width(), rect.height()); gradient.setColorAt(0, Qt::white); gradient.setColorAt(0.5, Qt::blue); gradient.setColorAt(1, Qt::green); painter->setBrush(gradient); painter->drawRect(rect); QStyleOptionViewItem newOptions = option; newOptions.font.setPixelSize(48); QItemDelegate::paint(painter, option, index); }
bool MySqlTableModel::setData(const QModelIndex &index, const QVariant &value, int role){ QAbstractItemModel::setData(index, Qt::black, Qt::BackgroundRole); return QSqlTableModel::setData(index, value, role);}
QVariant MySqlTableModel::data(const QModelIndex &idx, int role) const{ switch(role){ case Qt::BackgroundRole: return Qt::black; } return QSqlTableModel::data(idx, role);}