您的位置:首页 > 编程语言 > Qt开发

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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: