简体   繁体   English

Qt与父级调整子控件的大小

[英]Qt resizing child widgets with the parent

I have made a custom widget in the UI designer which consists of the main window(which I resized to 700 width and 30 height) and inside it I have a QLineEdit that is 30 height and 770 width and next to it a [X] button that is 30 width and 30 height. 我已经在UI设计器中制作了一个自定义窗口小部件,该窗口小部件由主窗口(大小调整为700宽度和30高度)组成,并且在其中有一个QLineEdit,其高度为30高度和770宽度,并在其旁边有一个[X]按钮那是30宽度和30高度。 I want to make it such that when the main window behind them is resized, the QLineEdit is resized too(horizontally), but the button always remains next to it. 我要这样设置,以便在调整它们后面的主窗口时,也可以(水平)调整QLineEdit的大小,但是该按钮始终保持在其旁边。 The problem is that right now when I resize the thing, the button gets obscured away. 问题是,当我调整大小时,按钮变得模糊不清。

try to add a QHBoxLayout to your custom widget first and then add the QLineEdit and the QPushButton into the layout. 尝试先将QHBoxLayout添加到自定义窗口小部件,然后将QLineEdit和QPushButton添加到布局中。

Layouts ensure that widgets stay properly ordered and resize correctly with the main widget. 布局可确保小部件保持正确的顺序并使用主小部件正确调整其大小。

It is also worth reading section "Adding Widgets to a Layout" in the Layout Management documentation 还值得阅读版面管理文档中的“向版面添加小部件”部分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM