Qt 图片适应QLabel控件大小(饱满缩放和按比例缩放)

Posted ybqjymy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Qt 图片适应QLabel控件大小(饱满缩放和按比例缩放)相关的知识,希望对你有一定的参考价值。

直接上代码:

1 QImage Image;
2     Image.load("d:/test.jpg");
3     QPixmap pixmap = QPixmap::fromImage(Image);
4     int with = ui->labPic->width();
5     int height = ui->labPic->height();
6     QPixmap fitpixmap = pixmap.scaled(with, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);  // 饱满填充
7     //QPixmap fitpixmap = pixmap.scaled(with, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);  // 按比例缩放
8     ui->labPic->setPixmap(fitpixmap);

 

以上是关于Qt 图片适应QLabel控件大小(饱满缩放和按比例缩放)的主要内容,如果未能解决你的问题,请参考以下文章