我想在像小方块一样大小的单元格中显示图像,这样当第一行充满图像时,它会自动进入下一行。我用verticalLayout
做了它,效果很好,但我不喜欢最终的结果。因为当图像数量非常大时,它会给我一些垂直线条,所以我看不清楚图像:
这是我的代码:
QStringList fileName =
QFileDialog::getOpenFileNames(this,
tr("Open Image"),
"C:/qt-win-opensource-src-4.5.0/bin/",
tr("Image Files(*.png *.jpg *.bmp *.avi *.gif)"));
QList<QPixmap> PixList;
for (int i=1;i<=fileName.size()-1;i++)
{
PixList.append(QPixmap(fileName.at(i)));
}
foreach(QPixmap pix, PixList){
// put the pixmaps one next to the other
PixLabel = new QLabel(this);
PixLabel->setScaledContents(true);
PixLabel->setPixmap(pix);
ui->verticalLayout->addWidget(PixLabel);
//ui->gridLayoutWidget->setVisible(true);
}
PixLabel->repaint();