PDA

View Full Version : How to move QPixmap in QTableView



Borland
1st March 2012, 03:12
Hi!
I have QTableView and insert QPixmap and QString using QAbstractTableModel:


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();
}
Looks like in the picture:
7455
Pixmap always inserted in left. But need pixmap top, text under the pixmap. How to do that?

ChrisW67
1st March 2012, 06:48
A custom delegate is one option. If you are actually displaying a list then the QListView in IconMode might be a better choice.

Borland
1st March 2012, 08:38
Thank you very mach! I displaying a list then the QListView in IconMode. It's really better.