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 604 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.
  • C Offline
    C Offline
    cerr
    wrote on 3 Apr 2020, 20:16 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 3 Apr 2020, 20:18 last edited by SGaist 4 Mar 2020, 20:19
      #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

      C 1 Reply Last reply 3 Apr 2020, 21:22
      3
      • S SGaist
        3 Apr 2020, 20:18

        Hi,

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

        C Offline
        C Offline
        cerr
        wrote on 3 Apr 2020, 21:22 last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0

        1/3

        3 Apr 2020, 20:16

        • Login

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