Eagle
Eagle

Reputation: 3474

Building Qt Gui from few classes together

Below is a short example of my Gui. I am trying to split my Gui in few parts. The elements of InputAxis should be on the same height (horizontal split) and self.recipient should be below them (vertical split).

In InputAxis I am trying to place a QLineEdit but in my Gui I don't see it.

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()

Upvotes: 0

Views: 42

Answers (1)

Eagle
Eagle

Reputation: 3474

the reason it did not work was this line:

self.form_layout = QtGui.QFormLayout()

It should be:

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

Upvotes: 1

Related Questions