Hi!
I have QTableView and insert QPixmap and QString using QAbstractTableModel:
{
if (!index.isValid())
if (role == Qt::TextAlignmentRole) {
return int(Qt::AlignBottom);
}
else if (role == Qt::DisplayRole) {
sz=5*index.row();
QString amount
= currencyAt
(index.
column()+sz
);
return amount;
}
else if (role == Qt::DecorationRole) {
sz=5*index.row();
QString amount
= currencyAt
(index.
column()+sz
);
qDebug()<<amount;
if(pixmap.isNull()) pixmap.load("radio.jpg");
pixmap.load(amount +".jpg");
pixmap=pixmap.scaled(50, 50, Qt::KeepAspectRatio);
return pixmap;
}
}
QString CurrencyModel
::currencyAt(int offset
) const {
if(offset >= currencyMap.size()) return "";
return (currencyMap.begin() + offset).key();
}
QVariant CurrencyModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::TextAlignmentRole) {
return int(Qt::AlignBottom);
}
else if (role == Qt::DisplayRole) {
sz=5*index.row();
QString amount = currencyAt(index.column()+sz);
return amount;
}
else if (role == Qt::DecorationRole) {
sz=5*index.row();
QPixmap pixmap;
QString amount = currencyAt(index.column()+sz);
qDebug()<<amount;
if(pixmap.isNull()) pixmap.load("radio.jpg");
pixmap.load(amount +".jpg");
pixmap=pixmap.scaled(50, 50, Qt::KeepAspectRatio);
return pixmap;
}
return QVariant();
}
QString CurrencyModel::currencyAt(int offset) const
{
if(offset >= currencyMap.size()) return "";
return (currencyMap.begin() + offset).key();
}
To copy to clipboard, switch view to plain text mode
Looks like in the picture:
Снимок.png
Pixmap always inserted in left. But need pixmap top, text under the pixmap. How to do that?
Bookmarks