设置QBoxLayout最大尺寸?
我显然在这里遗漏了一些东西,请赐教。
AttributeError: 'QVBoxLayout' object has no attribute 'setMaximumSize'
我已经阅读 Qt 文档有一段时间了,但似乎无法让它发挥作用
I clearly missing something here, please enlighten me.
AttributeError: 'QVBoxLayout' object has no attribute 'setMaximumSize'
I've been reading the Qt Docs for a while but just cant seem to be able to get this to work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不能直接设置 maximumSize 属性由布局动态确定。也许您正在尝试设置 QLayout.SizeConstraint< /a> 到 QLayout.SetMaximumSize?如果是这样,请参阅 QLayout.setSizeConstraint方法。否则,您应该调用 QWidget.setMaximumSize 如果您想要为给定的小部件指定确切的最大值。
You cannot set the maximumSize property directly as it is dynamically determined by the layout. Perhaps you are trying to set the QLayout.SizeConstraint to QLayout.SetMaximumSize? If so, then see the QLayout.setSizeConstraint method. Otherwise, you should call QWidget.setMaximumSize if you want to specify an exact maximum for a given widget.
正如该错误告诉您的那样,布局上没有
setMaximumSize
方法。QWidget
s 有这个方法。Just as that error tells you, there is no
setMaximumSize
method on a layout.QWidget
s have that method.AFAIK 您无法设置布局的最大尺寸。为什么你想要 - 这对我来说没有意义(哪个子小部件应该布局限制?)
关于
setMaximumSize
- 没有这样的布局方法。然而,您可以设置一个QLayout::SetMaximumSize
约束,但此约束适用于使用此布局布置的小部件,而不适用于布局本身。这意味着小部件的增长不能大于布局的最大尺寸 - 所以这与您需要的完全不同。我建议你重新考虑你的真正目标——也许可以通过其他方式实现。例如,您可以设置
QBoxLayout
布局的各个小部件的最大尺寸。AFAIK you can't set a maximal size for a layout. Why would you want to - it makes no sense to me (which child widget should the layout limit?)
Regarding
setMaximumSize
- there's no such method for layouts. There is however, aQLayout::SetMaximumSize
constraint which you can set, but this constraint applies to the widget that's laid out with this layout, not to the layout itself. It means that the widget can grow no larger than the maximal size of the layout - so this is quite different from what you need.I recommend you re-think your real goal - perhaps it can be achieved in some other way. For instance, you can set the maximal size for the individual widgets laid out by your
QBoxLayout
.