Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to align a GroupBox at the top of a VerticalLayout
Forum Updated to NodeBB v4.3 + New Features

How to align a GroupBox at the top of a VerticalLayout

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 2 Posters 778 Views 1 Watching
  • 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.
  • F Offline
    F Offline
    fvez_demtroys
    wrote on last edited by
    #1

    Hi,

    I am currently working on a PyQt5 application with Python 3.9.0.

    Screenshot
    I am trying to align a GroupBox to the top of a VerticalLayout in a HorizontalLayout.
    The HorizontalLayout contains a VerticalLayout (left side, Title 2 and Title 3) and a GroupBox (right side, Title 1).
    The VerticalLayout contains 2 GroupBoxes (Title 2 and Title 3).
    I decided to go with a VerticalLayout in a HorizontalLayout and not a GridLayout since the Title 3 GroupBox can be disabled.
    This makes it so the Title 2 GroupBox will fill in the space when the Title 3 GroupBox is hidden.

    As you can see in the image, the Title 2 GroupBox isn't aligned properly with the Title 1 GroupBox.
    I would like them to be at the same height, so when the Title 3 GroupBox is hidden, the Title 2 and Title 1 GroupBoxes would be the same exact size.

    I tried setting the contentMargins to 0 on all the components mentioned.
    HorizontalLayout.setContentsMargins(0, 0, 0, 0)
    VerticalLayout.setContentsMargins(0, 0, 0, 0)
    Title2GroupBox.setContentsMargins(0, 0, 0, 0)
    Title3GroupBox.setContentsMargins(0, 0, 0, 0)

    Nothing seems to change at all. I also tried playing with the spacing but would like to keep the spacing between Title 2 GroupBox and Title 3 GroupBox as it is currently.
    In my testing, the spacing didn't affect what I am trying to edit at all. Nothing seemed to affect the space I am trying to remove.

    Thanks for the help!

    Here is a code snippet to help visualize what I did.

            self.horizontalLayout = QHBoxLayout()
            self.horizontalLayout.setObjectName(u"horizontalLayout")
            self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
    
            self.verticalLayout = QVBoxLayout()
            self.verticalLayout.setObjectName(u"verticalLayout")
            self.verticalLayout.setContentsMargins(0, 0, 0, 0)
    
            self.horizontalLayout.addLayout(self.verticalLayout)
    
            self.verticalLayout.addWidget(self.groupBox_Title2)
    
            self.verticalLayout.addWidget(self.groupBox_Title3)
    
            self.horizontalLayout.addWidget(self.groupBox_Title1)
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What about putting groupBox_Title1 in its own vertical layout ?

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

      1 Reply Last reply
      1
      • F Offline
        F Offline
        fvez_demtroys
        wrote on last edited by
        #3

        Hi SGaist,

        Thanks for the suggestion, this seems to work just fine.

        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