当更多小部件放置在 QScrollArea 中时,如何调整其内容的大小 [英] How do i resize the contents of a QScrollArea as more widgets are placed inside

查看:33
本文介绍了当更多小部件放置在 QScrollArea 中时,如何调整其内容的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 提供答案:

<块引用>

widgetResizable : bool
此属性保存滚动区域是否应调整视图小部件的大小.如果此属性设置为 false(默认值),则滚动区域会遵循其小部件的大小.

设置为真.

I have a QScrollArea Widget, which starts empty;

It has a vertical layout, with a QGridLayout, and a vertical spacer to keep it at the top, and prevent it from stretching over the whole scroll area;

Elsewhere in the program, there is a QTextEdit, which when changed, has its contents scanned for "species" elements, and then they are added to the QGridLayout. Any species elements which have been removed are removed too. This bit works;

I have turned the vertical scrollbar on all the time, so that when it appears it does not sit on top of the other stuff in there. Note that the scroll bar is larger than the scroll box already though, despite not needing to be.

This is the problem. The scroll area seems to be preset, and i cannot change it. If i add more rows to the QGridLayout, the scroll area doesn't increase in size.

Instead, it stays the same size, and squeezes the QGridLayout, making it look ugly (at first);

And then after adding even more it becomes unusable;

Note that again, the scroll bar is still the same size as in previous images. The first two images are from Qt Designer, the subsequent 3 are from the program running.

If I resize the window so that the QScrollArea grows, then I see this:

Indicating that there's some layout inside the scroll area that is not resizing properly.

My question is; what do I need to do to make the scrollable area of the widget resize dynamically as I add and remove from the QGridLayout?

解决方案

The documentation provide an answer :

widgetResizable : bool
This property holds whether the scroll area should resize the view widget. If this property is set to false (the default), the scroll area honors the size of its widget.

Set it to true.

这篇关于当更多小部件放置在 QScrollArea 中时,如何调整其内容的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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