pbreach
pbreach

Reputation: 17017

Inserting layout into QDialog when signal is emitted from combobox

I have a ui created in qtdesigner that looks like this:

enter image description here

and I want to insert another layout containing a couple of widgets between the groupbox titled "Equation" and the layout containing the two groupboxes titled "Subscripts" and "Connected Elements".

The reason I'm not sure how to insert this additional layout is that when I look at the object inspector in qtdesigner I see this:

enter image description here

which doesn't tell me the name of the vertical layout that contains all the other widgets and layouts in the dialog window.

I am loading up the ui as follows:

from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4 import uic

class EquationEditor(QDialog):

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

        uic.loadUi('equation_editor.ui', self)

        # Insert a layout containing a couple of widgets on index change of
        # the combobox
        self.typeBox.currentIndexChanged.connect(self.enableInitialValueEntry)

    def enableInitialValueEntry(self):
        vartype = self.typeBox.currentText()

        if vartype == "Stock":
            hbox = QHBoxLayout()
            hbox.addStretch(1)

            hbox.addWidget(QLabel("Initial Value"))
            hbox.addWidget(QLineEdit())

            #How can I insert the layout `hbox`?

Upvotes: 1

Views: 501

Answers (1)

ekhumoro
ekhumoro

Reputation: 120688

The layout that contains all the others will be the dialog's layout, so you can try something like this:

    def enableInitialValueEntry(self):
        ...
        if vartype == "Stock":
            ...
            main_layout = self.layout()
            main_layout.insertLayout(2, hbox)

Upvotes: 1

Related Questions