我尝试加载图片,但加载的图片非常小。我其实不太了解QLabel的用法。有人可以帮我弄清楚如何调整加载图像的大小吗?
ImageViewer::ImageViewer()
{
imageLabel = new QLabel;
imageLabel->setBackgroundRole(QPalette::Base);
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
imageLabel->setScaledContents(true);
scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidget(imageLabel);
setCentralWidget(scrollArea);
resize(500, 400);
}
void ImageViewer::loadFile(const QString &fileName)
{
if (!fileName.isEmpty()) {
image = new QImage(fileName);
if (image->isNull()) {
QMessageBox::information(this, tr("Image Viewer"),
tr("Cannot load %1.").arg(fileName));
return;
}
imageLabel->setPixmap(QPixmap::fromImage(*image));
scaleFactor = 1;
updateActions();
}
}