I've tried to put them into a QListWidget as icons in ordinary items, but they get too small. I wish to have them 50x50 pixels.
How can I get them in that size?
I've tried to put them into a QListWidget as icons in ordinary items, but they get too small. I wish to have them 50x50 pixels.
How can I get them in that size?
Hi,
QListWidget has a property inherited from QAbstractItemView: iconSize
call setIconSize(QSize(x,y)) to change the size of the icons in the list, that worked for me
Hi,
Try this code. It will help you
in your header file
enum { NumModes = 4, NumStates = 2 };
QStringList files;
QStringList filters;
QString fileName;
QDir directory;
QPixmap pixmap ;
int r, c, NumStates_New, HEIGHT;
QGridLayout *SnapLayout;
QIcon icon;
QSize size;
QLabel *pixmapLbl;
void YourClass::LoadImages(){
int COLUMN;
filters << "Picture*" ;
directory.setNameFilters(filters);
files = directory.entryList(filters, QDir::Files | QDir::NoSymLinks);
c=0; COLUMN = 2;
NumStates_New = 0;
NumStates_New = files.size()/2;
if ( files.size()%2 >0 ) NumStates_New++;
QLabel *pixmapLabels [NumStates_New] [2];
pixmapLabels [NumStates_New] [2];
for (int i = 0; i < NumStates_New; ++i) {
for (int j = 0; j < COLUMN; ++j) {
pixmapLabels[i][j] = createPixmapLabel();
pixmapLabels[i][j]->resize(5,5);
SnapLayout->addWidget(pixmapLabels[i][j], i + 1, j + 1 );
}
}
r=0, c=0;
for (int i = 0; i < files.size(); ++i) {
fileName = files.at(i).toLocal8Bit().constData(); QImage image(fileName);
if (!image.isNull()){
icon.addPixmap(QPixmap::fromImage(image), QIcon::Normal, QIcon::On);
}
this->icon = icon;
this->size = QSize(110,102);
QPixmap pixmap = icon.pixmap(size, QIcon::Normal, QIcon::On);
pixmapLabels[r][c]->setPixmap(pixmap);
pixmapLabels[r][c]->setToolTip(fileName);
c++; if (c>=COLUMN) { c=0; r++; }
} }
QLabel *YourClass::createPixmapLabel()
{
QLabel *label = new QLabel;
label->setEnabled(true);
label->setAlignment(Qt::AlignCenter);
label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
label->setAutoFillBackground(true);
label->setMinimumSize(110,102);
return label;
}
and Call this function in your program
Bookmarks