If some cell data has been changed and you need another cell's contents to be updated in turn you should do that via the model, something like this:
{
int row = index.row();
int col = index.column();
if(role == Qt::EditRole && col == SOME_SPECIAL_COLUMN)
{
// do editing
// update entire row
emit dataChanged(left, right);
return true;
}
return false;
}
bool TableModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
int row = index.row();
int col = index.column();
if(role == Qt::EditRole && col == SOME_SPECIAL_COLUMN)
{
// do editing
// update entire row
QModelIndex left = index(row, 0);
QModelIndex right = index(row, columnCount() - 1);
emit dataChanged(left, right);
return true;
}
return false;
}
To copy to clipboard, switch view to plain text mode
Inside your custom delegate's paint method you can paint the background like this
{
// figure out how the cell should be drawn
// ...
QColor background
= index.
model()->data
(index, Qt
::BackgroundRole).
value<QColor>
();
painter->fillRect(option.rect, background);
}
void CustomDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
// figure out how the cell should be drawn
// ...
QColor background = index.model()->data(index, Qt::BackgroundRole).value<QColor>();
painter->fillRect(option.rect, background);
}
To copy to clipboard, switch view to plain text mode
A delegate is usually responsible for drawing a cell's contents. So if you provide a custom delegate there should be no class "overpainting" that cell or its background. If I still miss your point you need to provide some code.
Bookmarks