从几个班级一起建立Qt Gui

时间:2016-10-08 05:42:05

标签: python qt pyqt pyside

以下是我的Gui的简短示例。我想把我的Gui分成几个部分。 InputAxis 的元素应该在同一高度(水平分割), self.recipient 应该在它们之下(垂直分割)。

InputAxis 中我试图放置一个 QLineEdit 但是在我的Gui中我没有看到它。

import sys
from PySide import QtCore
from PySide import QtGui

class InputAxis(object):
    def __init__(self):
        self.frame = QtGui.QFrame()
        self.input_interface = QtGui.QLineEdit()
        self.form_layout = QtGui.QFormLayout()

    def genAxis(self):
        self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
        self.form_layout.addRow('&Input:', self.input_interface)

        return self.frame

class Window(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self, parent = None)

        self.layout = QtGui.QVBoxLayout()
        self.form_layout = QtGui.QFormLayout()

        self.axes = list()
        self.axes.append(InputAxis())
        self.axes.append(InputAxis())

        self.splitter1 = QtGui.QSplitter(QtCore.Qt.Horizontal)
        for axis in self.axes:
            self.splitter1.addWidget(axis.genAxis())
        self.form_layout.addWidget(self.splitter1)

        self.setMinimumWidth(400)
        self.recipient = QtGui.QLineEdit(self)
        # Add it to the form layout with a label
        self.form_layout.addRow('&Recipient:', self.recipient)
        # Add the form layout to the main VBox layout
        self.layout.addLayout(self.form_layout, 0)
        # Set the VBox layout as the window's main layout
        self.setLayout(self.layout)
        QtGui.QApplication.setStyle( QtGui.QStyleFactory.create('Cleanlooks') )

    def run(self):
        self.show()

def main():
    qt_app = QtGui.QApplication(sys.argv)
    window = Window()
    window.run()
    sys.exit(qt_app.exec_())

if __name__=="__main__":
    main()

1 个答案:

答案 0 :(得分:1)

它不起作用的原因是这一行:

self.form_layout = QtGui.QFormLayout()

应该是:

self.form_layout = QtGui.QFormLayout(self.frame)