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. In QT Designer, how to center a widget in a horizontal layout?

In QT Designer, how to center a widget in a horizontal layout?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 270 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.
  • M Online
    M Online
    Mizmas
    wrote on last edited by Mizmas
    #1

    For example the QLineEdit in the middle is off center because there's a QLabel to the left, but I want the line edit to be in the middle:
    Screenshot_1.png

    Or here I want the "MIDI Output Mode" widget in the middle as well, but since the other widgets are different sized, it gets placed off center:
    Screenshot_4.png

    In both examples the widgets are in a QFrame which has the horizontal layout applied to it.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      A grid layout with column stretch factors '1,1,1'. The label right-align in the left cell, the edit in the centre cell, and a spacer or other widget in the right cell.
      056d1fdb-51d1-4462-8286-0adb149c1b87-image.png ![alt text](image url)

      M 1 Reply Last reply
      1
      • C ChrisW67

        A grid layout with column stretch factors '1,1,1'. The label right-align in the left cell, the edit in the centre cell, and a spacer or other widget in the right cell.
        056d1fdb-51d1-4462-8286-0adb149c1b87-image.png ![alt text](image url)

        M Online
        M Online
        Mizmas
        wrote on last edited by
        #3

        @ChrisW67 It works, but I was hoping there was a more intuitive way :D

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SimonSchroeder
          wrote on last edited by
          #4

          Use nested layouts. The outer horizontal layout has 3 columns with the line edit in the middle. For the first example you gave there would be nested horizontal layout in the first column containing the spacer and the label. The outer layout will try to equally space everything. However, below a certain size the layout might still become asymmetric.

          1 Reply Last reply
          2

          • Login

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