You are not logged in.
I'm working on a Qt project and trying to create a table which has a column of images. So I created QTableWidgetItems for each of the cells in the column and used setIcon() to apply the images to the cells as QPixMaps. To resize the images I'm trying QPixMap::scaled, however it doesn't seem to be affecting the size of the images which are altogether too tiny... Does anyone have any ideas? I've included a screenshot below as well as a code snippet.
QTableWidgetItem *mediaCell = new QTableWidgetItem();
mediaCell->setIcon(QIcon(QPixmap("mypic.jpg").scaled(500, 500, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
mediaTable->setItem(ctr, currCol++, mediaCell);
Last edited by tony5429 (2011-09-11 12:56:00)
Offline
@tony5429: Please read the documentation of QIcon:
The simplest use of QIcon is to create one from a QPixmap file or resource, and then use it, allowing Qt to work out all the required icon styles and sizes.
In short, it doesn't matter whether you create an icon from the original or from a scaled pixmap, the size is simply ignored. Qt always chooses the "best" size for an icon, and the best size for an icon in a table row is obviously the height of this row.
If you want to show "images", not icons, try "mediaCell->setData(Qt.ItemDecorationRole, QPixmap("mypic.jpg"))". Even better, abandon "QTableWidget", and write a proper "QTableModel" for use with "QTableView".
Offline
Thank you so much! This worked for me...
QTableWidgetItem *mediaCell = new QTableWidgetItem();
mediaCell->setData(Qt::DecorationRole, QPixmap("mypic.jpg").scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation));
mediaTable->setItem(ctr, currCol++, mediaCell);
Offline