Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved problem with aligning text underneath buttons

    General and Desktop
    pyqt4 layout qlabel qpushbutton
    2
    3
    267
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cerr
      cerr last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by SGaist

        Hi,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        cerr 1 Reply Last reply Reply Quote 3
        • cerr
          cerr @SGaist last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • First post
            Last post