的左侧有一些小部件水平居中:窗口小部件水平和标签集中到这些小部件
class TestWidget(QWidget):
def __init__(self):
super().__init__()
self._init_ui()
def _init_ui(self):
edit1_label = QLabel("Edit1")
edit2_label = QLabel("Edit2")
edit3_label = QLabel("Edit3")
edit1 = QLineEdit()
edit2 = QLineEdit()
edit3 = QLineEdit()
layout = QVBoxLayout()
layout.addWidget(edit1)
layout.addWidget(edit2)
layout.addWidget(edit3)
layout.addStretch()
hlayout = QHBoxLayout()
hlayout.addLayout(layout)
self.setLayout(hlayout)
self.setAttribute(Qt.WA_StyledBackground)
def _main():
app = QApplication([''])
app.setStyleSheet("""
TestWidget {
min-height: 400px;
max-height: 400px;
min-width: 600px;
max-width: 600px;
}
TestWidget QLineEdit {
min-height: 2em;
max-height: 2em;
min-width: 20em;
max-width: 20em;
}
""")
w = TestWidget()
w.show()
app.exec_()
我想标签(edit1_label,edit2_label,edit3_label)的地方进行编辑的左(EDIT1, edit2,edit3)。但编辑应该在表单上水平居中。它如何实施?
更新:新增例如图形(请注意QLineEdits都在表格上水平居中):
总之,你想把QLabels放在QLineEdits的一面wi而不是分散他们 – eyllanesc
是的,你是对的,@eyllanesc – Aleksey
你可能想看看QFormLayout。 – HashSplat