我可以在QtCreator中预览布局内的固定尺寸项目吗?(Can I preview fixed size item inside layout in QtCreator?)

编程入门 行业动态 更新时间:2024-10-23 14:24:19
我可以在QtCreator中预览布局内的固定尺寸项目吗?(Can I preview fixed size item inside layout in QtCreator?)

所以我有一个QDialog及其在垂直布局中的设置。 我正在添加各种线路输入和标签。 在顶部,我有一个特定的QLabel加载QPixmap并显示图像。 现在,即使当我使用scaledContents(true) ,图像scaledContents(true)膨胀到原来的大小。

我无法设置几何细节,因为它们在QtCreator中被禁用,因为我处于Verical布局中,所以所有内容都会自动缩放。

我使用QDialog的构造函数中的setFixedSize() ,但这并没有在QtCreator中给我正确的预览。

如何在QtCreator中设置内部布局的固定大小?

So I have a QDialog and its set in Vertical layout. I am adding various line inputs and labels. On top I have one particular QLabel that loads QPixmap and displays image. Now even when I use scaledContents(true) the image tends to bloat up into its original size.

I cannot set geometry details as they are disabled in QtCreator for I am inside a Verical layout, so everything is scaled automatically.

I resorted to using setFixedSize() from QDialog's constructor, but this doesnt give me correct preview in QtCreator.

How to set a fixed size inside layout in QtCreator?

最满意答案

您需要为QLabel的QPixmap对象选择Qt::KeepAspectRatio

例如:

QPixmap px; QLabel label; label->setPixmap(px.scaled(label->width(), label->height(),Qt::KeepAspectRatio));

You need to select Qt::KeepAspectRatio for the QPixmap object within QLabel

For example:

QPixmap px; QLabel label; label->setPixmap(px.scaled(label->width(), label->height(),Qt::KeepAspectRatio));

更多推荐

本文发布于:2023-08-05 05:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1427214.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布局   尺寸   项目   QtCreator   preview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!