PySide - QFormLayout - 对齐问题

时间:2015-12-04 00:06:31

标签: python pyside

我正在尝试将QFromLayout用于PySide面板,但我无法调整工作。我希望所有字段都垂直排列。目前他们没有排队,我猜这个标签的长度是多少?我尝试使用bot setHorizo​​ntalAlignment()并用白色空格填充标签,但没有运气。

编辑:

simplistic logging facility

基本上我想要所有"第2列"垂直对齐。

有什么想法吗? Here's a better example of what's not aligned.

import sys
from PySide.QtGui import *
from PySide.QtCore import *

class MyPanel(QWidget):

    def __init__(self, parent = None):
        super(MyPanel, self).__init__(parent)

        self.grp1 = QGroupBox()
        self.form_layout1 = QFormLayout()

        self.drop1 = QComboBox()
        self.drop1.addItems(["item1", "item2"])
        self.form_layout1.addRow('drop', self.drop1)

        self.line1 = QLineEdit()
        self.form_layout1.addRow("long long line", self.line1)

        self.btn1 = QPushButton("button")
        self.form_layout1.addRow("", self.btn1)

        self.grp2 = QGroupBox()
        self.form_layout2 = QFormLayout()

        self.check2 = QCheckBox()
        self.form_layout2.addRow("checkbox", self.check2)

        self.line2 = QLineEdit()
        self.form_layout2.addRow("line", self.line2)

        # Set layouts.
        self.grp1.setLayout(self.form_layout1)
        self.grp2.setLayout(self.form_layout2)

        # Main layout.
        self.layout = QVBoxLayout()

        self.layout.addWidget(self.grp1)
        self.layout.addWidget(self.grp2)

        self.setLayout(self.layout)

# Show
app = QApplication(sys.argv)
panel = MyPanel()
panel.show()
app.exec_()

0 个答案:

没有答案