Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

problem with aligning text underneath buttons



  • Hi,

    I have a layout that contains two buttons centered like so:

    self.foo_layout = QtGui.QHBoxLayout(self.exit_frame)
    self.foo_layout.addItem(self.horizontal_spacer)
    self.foo_layout.addWidget(self.one_btn)
    self.foo_layout.addWidget(self.two_btn)
    self.foo_layout.addItem(self.horizontal_spacer)
    

    Now I need to add two labels to be displayed underneath the buttons, I create them like:

    self.baz_lab = QtGui.QLabel("Lab1")
    self.qux_lab = QtGui.QLabel("Lab2")
    

    And I thought I could modify the above code like (below example only shows label for one_btn):

    self.foo_layout = QtGui.QHBoxLayout(self.exit_frame)
    self.foo_layout.addItem(self.horizontal_spacer)
    self.bar_lay = QtGui.QVBoxLayout()
    self.bar_lay.addWidget(self.one_btn) 
    self.bar_lay.addWidget(self.baz_lab) 
    self.foo_layout.addWidget(self.bar_lay)
    self.foo_layout.addWidget(self.two_btn)
    self.foo_layout.addItem(self.horizontal_spacer)
    

    but I get

    TypeError: QBoxLayout.addWidget(QWidget, int stretch=0, Qt.Alignment alignment=0): argument 1 has unexpected type 'QVBoxLayout 
    

    how do I get the labels shown undernbeath the buttons?


  • Lifetime Qt Champion

    Hi,

    To add a layout to a layout there's the "addLayout" method.



  • This post is deleted!