alketi
9th December 2014, 21:57
I want to populate cells on a QTableView with a brush pattern + color. (Qt 5.2.1)
In my QAbstractItemModel subclass my data method is as follows:
QVariant MyTableModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::TextAlignmentRole)
return Qt::AlignCenter;
if (role == Qt::BackgroundRole)
{
QBrush brush(Qt::BDiagPattern);
brush.setColor(QColor(Qt::red));
return brush;
}
if (role != Qt::DisplayRole && role != Qt::EditRole)
return QVariant();
return (m_data.getValueText());
}
The result of this is that each cell has a different variant of the "BDiagPattern" pattern, as seen in the attached picture!
And, if I manually resize the tableview cells, picture 1 --> picture 2, the pattern variant continues to change from cell to cell.
Am I missing something, or is this a bug??
10797 10798
In my QAbstractItemModel subclass my data method is as follows:
QVariant MyTableModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::TextAlignmentRole)
return Qt::AlignCenter;
if (role == Qt::BackgroundRole)
{
QBrush brush(Qt::BDiagPattern);
brush.setColor(QColor(Qt::red));
return brush;
}
if (role != Qt::DisplayRole && role != Qt::EditRole)
return QVariant();
return (m_data.getValueText());
}
The result of this is that each cell has a different variant of the "BDiagPattern" pattern, as seen in the attached picture!
And, if I manually resize the tableview cells, picture 1 --> picture 2, the pattern variant continues to change from cell to cell.
Am I missing something, or is this a bug??
10797 10798