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 vertically center align the QLabel and a QWidget of a QFormLayout row ?
QtWS25 Last Chance

How to vertically center align the QLabel and a QWidget of a QFormLayout row ?

Scheduled Pinned Locked Moved Solved Qt for Python
6 Posts 2 Posters 277 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.
  • N Offline
    N Offline
    Nlight
    wrote on 24 Feb 2025, 19:23 last edited by
    #1

    HI guys, as the title says :
    How to vertically center align the QLabel and a QWidget of a QFormLayout row ?

    in each row, there is the QLabel on the left column, and on the right I use a custom QWidget that host several QPushButtons displaying only an icon (which size is manually set at the button creation).

    The hierarchy of the custom QWidget could be described as this

    Custom(QWidget) :
        layout : QHBoxLayout
            IconButton
            ...
    

    I've tried to apply to each QLabel int the QFormLayout : widget.setAlignement(Qt.AlignmentFlag.AlignVCenter)
    however the vertical alignement between the Label on the left side and the widget on the right side remain set to their respective top.

    Ad before drowning you with everything else I tried, maybe one of you had already faced such a situation.

    1 Reply Last reply
    0
    • N Offline
      N Offline
      Nlight
      wrote on 24 Feb 2025, 22:39 last edited by
      #6

      Hmmm... actually, I finally made it : and the solution was... to remove margins from theQHBoxLayout of the QWidget !
      Jesus ! I'll have to carefully remember that one 😅

      1 Reply Last reply
      1
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 24 Feb 2025, 19:42 last edited by
        #2

        Hi,

        Did you already tried with the QFormLayout
        ::labelAlignment
        ?

        There's also formAlignment.

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

        N 1 Reply Last reply 24 Feb 2025, 20:53
        0
        • N Offline
          N Offline
          Nlight
          wrote on 24 Feb 2025, 20:29 last edited by
          #3

          Hmmm.... I must say I think not, I'll dig it and come back if necessary, thanks 🙂

          1 Reply Last reply
          0
          • S SGaist
            24 Feb 2025, 19:42

            Hi,

            Did you already tried with the QFormLayout
            ::labelAlignment
            ?

            There's also formAlignment.

            N Offline
            N Offline
            Nlight
            wrote on 24 Feb 2025, 20:53 last edited by
            #4

            @SGaist Well... that was worth a shot, but nope, does not change a thing.
            QFormLayout.setLabelAlignment() does handle the horizontal alignment
            And QFormLayout.setFormAlignment() handles the alignment of where the set of rows begin and end, so it's not the vertical alignment of both elements of a single row...

            Hmmm... I'll take the time to look at the docs more attentively, without rush... regardless, thanks.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 24 Feb 2025, 20:57 last edited by
              #5

              Then the next step would likely be to create a custom QProxyStyle that handle that part.

              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
              0
              • N Offline
                N Offline
                Nlight
                wrote on 24 Feb 2025, 22:39 last edited by
                #6

                Hmmm... actually, I finally made it : and the solution was... to remove margins from theQHBoxLayout of the QWidget !
                Jesus ! I'll have to carefully remember that one 😅

                1 Reply Last reply
                1
                • N Nlight has marked this topic as solved on 24 Feb 2025, 22:52

                3/6

                24 Feb 2025, 20:29

                • Login

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