我正在学习PyQt5。如何删除Qlable下的巨大空间:
https://hizliresim.com/Lr9ujj
这是我的代码:
class TftpTab(QWidget):
def __init__(self):
super().__init__()
host = QLabel("Host: ")
hostEdit = QLineEdit()
layout = QVBoxLayout()
layout.addWidget(host)
layout.addWidget(hostEdit)
Tags:
将标签的垂直大小策略设置为
Fixed
。 您的问题是行编辑设置了Fixed
,但标签没有设置。因此,标签将随着父窗口小部件(在您的示例中为tab)而增长有关可能的选项,请参见https://doc.qt.io/qt-5/qsizepolicy.html#Policy-enum
如果没有小部件来填充空间,控制窗口增长位置的另一个可行工具是分隔符,您也可以将其添加到布局中。在您的案例中,在hostEdit下方添加的垂直间隔符
在我看来,你最好使用
QFormLayout
更新
相关问题 更多 >
编程相关推荐