QLabel :: setPixmap()和QScrollArea :: setWidget() [英] QLabel::setPixmap() and QScrollArea::setWidget()

查看:269
本文介绍了QLabel :: setPixmap()和QScrollArea :: setWidget()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在跟踪一个bug,归结为这 - 如果你在滚动区域内显示一个图像标签,标签将不会被调整为图像的大小如果 QLabel :: setPixmap )在之后调用 QScrollArea :: setWidget()

I've been tracking down a bug that boils down to this - if you show an image label inside a scroll area, the label will not be resized to the image's size if QLabel::setPixmap() is called after QScrollArea::setWidget().

此示例说明了问题,只需使用计算机上的某个实际图片替换 /path/to/some/image.png

This example illustrates the problem, just replace /path/to/some/image.png with some real image on your computer:

QScrollArea *scrollArea = new QScrollArea;
QLabel *label = new QLabel(scrollArea);
scrollArea->setWidget(label);
label->setPixmap(QPixmap("/path/to/some/image.png"));
scrollArea->show();

如果你换行以调用 setPixmap() 之前 setWidget(),标签将正确调整大小。

If you swap the lines to call setPixmap() before setWidget(), the label will be properly resized.

推荐答案

设置滚动区域的 widgetResizable 属性为true:

Set your scroll area's widgetResizable property to true:

scrollArea->setWidgetResizable(true);

这篇关于QLabel :: setPixmap()和QScrollArea :: setWidget()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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