Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. problem with aligning text underneath buttons
QtWS25 Last Chance

problem with aligning text underneath buttons

Scheduled Pinned Locked Moved Solved General and Desktop
pyqt4layoutqlabelqpushbutton
3 Posts 2 Posters 605 Views
  • 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.
  • cerrC Offline
    cerrC Offline
    cerr
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      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

      cerrC 1 Reply Last reply
      3
      • SGaistS SGaist

        Hi,

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

        cerrC Offline
        cerrC Offline
        cerr
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved