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

时间:2020-06-19 13:25:03   收藏:0   阅读:420

直接上代码:

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);

 

原文:https://www.cnblogs.com/ybqjymy/p/13162465.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!