如何将QLabel的大小设置为pixmap中的图像大小? [英] How to set QLabel's size to that of the image in its pixmap?

查看:3165
本文介绍了如何将QLabel的大小设置为pixmap中的图像大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的应用程序使用QT,最后使用QLabel来显示图像。但是,它显示为裁剪。
如何将QLabel的大小设置为其pixmap之一?如果pixmap发生变化会如何改变呢?

I am using QT for my application, and ended up using QLabel to display image. However, it is displayed cropped. How can the size of QLabel set to one of its pixmap? How can that be done in such a way that it would change if the pixmap changes?

推荐答案

// Call this function whenever you want to change the label's pixmap
void SetPixmapLabel(QLabel * myLabel, const QPixmap & pixmap)
{
   myLabel->setPixmap(pixmap);
   myLabel->setFixedSize(pixmap.size());
}

这篇关于如何将QLabel的大小设置为pixmap中的图像大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆