I am trying to display an image with a QAbstractTableModel . I tried to return QPixmap as QVariant from data() , but it only creates empty cells when I expect each cell in the second column to have a 20x20 black square.
This is my code:
QVariant MySqlTableModel::data(const QModelIndex &idx, int role = Qt::DisplayRole) const { if (role == Qt::DisplayRole && idx.column() == 1) { QPixmap pixmap(20,20); QColor black(0,0,0); pixmap.fill(black); return pixmap; } return QSqlTableModel::data(idx, role); }
source share