简体   繁体   English

如何将 QLabel 的大小设置为其像素图中的图像大小?

[英]How to set QLabel's size to that of the image in its pixmap?

I am using QT for my application, and ended up using QLabel to display image.我在我的应用程序中使用 QT,最后使用 QLabel 来显示图像。 However, it is displayed cropped.但是,它显示为裁剪。 How can the size of QLabel set to one of its pixmap? QLabel 的大小如何设置为其像素图之一? 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());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM