qt无法展开布局?
好吧,这是我的问题:
我有一个垂直布局,其中包含一个 QPlainTextEdit 和一个水平布局(包含 2 个 QPushButtons),位于文本编辑下方。
垂直布局只是 GUI 的一部分,并根据屏幕分辨率调整大小。顺便提一句。它是一个移动应用程序,所以屏幕上没有太多空间。
按钮有一些动态设置的文本,我从一开始就不知道要手动编码。
当按钮中的文本很大并且我的整个垂直布局扩展以适合按钮时,就会出现我的问题。
如何使垂直布局不可扩展?请注意,由于屏幕分辨率不同,这与“固定”不同。 如果按钮不合适,我只想剪掉按钮,但保持布局宽度不变。
无论如何要这样做吗?
Ok, here is my problem:
I have a vertical layout which contains a QPlainTextEdit and a horizontal layout (containing 2 QPushButtons) below the text edit.
The vertical layout is just a part of GUI, and gets resized depending on screen resolution. Btw. it is a mobile app, so I don't have a lot of space on screen.
Push buttons have some text which is dynamically set, I don't know it from the beginning to code it manually.
My problem occurs when the text in push buttons is big, and my whole vertical layout is expanded to fit the buttons.
How can I make the vertical layout unexpandable? note, that this is different from "fixed" because of different screen resoulutions.
I'd just like the clip the buttons if they do not fit, but keep the layout width untouched.
Anyway to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要设置按钮的最大宽度,而不是布局,布局只是加宽以适应更宽的按钮。查看 QPushButton 上的文档 并查找名为 setMaximumSize 或的 QWidget 继承函数设置最大宽度。
You'll need to set the maximum width for the buttons, not the layout, which is only widening to fit the wider buttons. Check out the docs on QPushButton and look for QWidget inherited functions called setMaximumSize or setMaximumWidth.
当按钮尺寸合适时,您始终可以在按钮上使用 GetWidth() ,然后使用该值设置MaximumWidth,因为您通常不知道这一点。选择适当的默认文本大小/值并使用它来创建“动态”默认值,因为这是在不同大小的屏幕上进行的。
You can always GetWidth() on the button when it is an appropriate size, then setMaximumWidth using that value since you wouldn't ordinarily know this. Pick an appropriate default text size/val and use that to create your "dynamic" default since this is going on screens of varying size.