Qt 图片适应QLabel控件大小(饱满缩放和按比例缩放)
2017-09-06 16:02
2991 查看
直接上代码:
QImage Image;
Image.load("d:/test.jpg");
QPixmap pixmap = QPixmap::fromImage(Image);
int with = ui->labPic->width();
int height = ui->labPic->height();
QPixmap fitpixmap = pixmap.scaled(with, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); // 饱满填充
//QPixmap fitpixmap = pixmap.scaled(with, height, Qt::KeepAspectRatio, Qt::SmoothTransformation); // 按比例缩放
ui->labPic->setPixmap(fitpixmap);
QImage Image;
Image.load("d:/test.jpg");
QPixmap pixmap = QPixmap::fromImage(Image);
int with = ui->labPic->width();
int height = ui->labPic->height();
QPixmap fitpixmap = pixmap.scaled(with, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); // 饱满填充
//QPixmap fitpixmap = pixmap.scaled(with, height, Qt::KeepAspectRatio, Qt::SmoothTransformation); // 按比例缩放
ui->labPic->setPixmap(fitpixmap);
相关文章推荐
- Qt(伪)自适应屏幕大小和控件按比例缩放的几个问题
- QT获取控件中心点,图片按比例缩放
- Qt之图片自适应QLabel的大小
- Qt中窗体控件按照比例缩放,自适应窗口大小进行布局
- 一个 Qt 显示图片的控件(继承QWidget,使用QPixmap记录图像,最后在paintEvent进行绘制,可缩放)
- JS控制图片显示的大小(图片等比例缩放)
- 微信小程序开发之图片等比例缩放 获取屏幕尺寸图片尺寸 自适应
- ASP.NET中FileUpload控件上传图片时等比例缩放,然后保存到数据库
- 图片按比例缩放大小
- 图片宽度为控件宽度,高度按比例缩放
- QT中给各控件增加背景图片(可缩放可旋转)的几种方法
- iOS UILabel根据字数自适应宽高以及控件按屏幕大小按比例缩放
- 实现图片在控件中的按比例缩放方法
- C#picturebox或者Dev控件 PictureEdit 按比例的缩放加载图片
- JS控制图片显示的大小(图片等比例缩放)
- QT中给各控件增加背景图片(可缩放可旋转)的几种方法
- MFC窗口和控件大小等比例缩放
- Qt学习笔记之图片显示(自动调整大小适应设计的范围)
- 在Picture Control控件上显示JPG图片并让图片适应控件的大小
- JS控制图片显示的大小(图片等比例缩放)