QLabel 显示图片大小的自适应
from:
1、https://blog.csdn.net/mangobar/article/details/52300155
2、https://blog.csdn.net/kfy2011/article/details/77867609
设置实现:
qLabel->setScaleContents(true);
上述代码可以在Qt Creator中进行,选择需要设置的QLabel,勾选 scaledContents 属性。
代码实现:
QImage Image;
Image.load(<span style="font-family:Consolas, 'Courier New', Courier, mono, serif;line-height:18px;background-color:rgb(248,248,248);">"d:/test.jpg"</span>); 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);
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
