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. QFormLayout with QVBoxLayout

QFormLayout with QVBoxLayout

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 646 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.
  • L Offline
    L Offline
    Leon_2001
    wrote on last edited by
    #1

    Hi everyone,

    I want to make a FormLayout, where the label is a QLabel and the form right is QVBoxLayout. Unfortunately, the alignment doesn't work the way I want it.

    QFormLayout* mLayout = new QFormLayout;
    
        QLabel* label1 = new QLabel(QStringLiteral("Name"));
        QLabel* label2 = new QLabel(QStringLiteral("Name"));
        QLabel* label3 = new QLabel(QStringLiteral("Name"));
    
        QVBoxLayout* vbox = new QVBoxLayout;
        vbox->addWidget(label2);
        vbox->addWidget(label3);
    
        mLayout->addRow(label1, vbox);
    
        this->setLayout(mLayout);
    

    0_1567504170748_11eddb48-e84d-43bb-86d0-9efb42a914de-image.png

    I would like to have the left label on the same height as the right upper label in the QVBoxLayout.

    Turning on borders:

    0_1567504259014_93b94587-903b-4dfe-a0bf-b9ddfa27876d-image.png

    the label left is stretched for some reason and I can't figure out why.

    Any help would be appreciated!

    GerhardG 1 Reply Last reply
    0
    • S Offline
      S Offline
      spobit
      wrote on last edited by
      #2

      maybe you should set fixed size.

      void QWidget::setFixedSize(int w, int h)
      
      1 Reply Last reply
      0
      • L Offline
        L Offline
        Leon_2001
        wrote on last edited by
        #3

        Indeed it works:

        label1->setFixedHeight(label1->sizeHint().height());
        

        But it seems more like a hacky solution, what is the reason that the sizeHint is not respected in the first place?

        1 Reply Last reply
        0
        • L Leon_2001

          Hi everyone,

          I want to make a FormLayout, where the label is a QLabel and the form right is QVBoxLayout. Unfortunately, the alignment doesn't work the way I want it.

          QFormLayout* mLayout = new QFormLayout;
          
              QLabel* label1 = new QLabel(QStringLiteral("Name"));
              QLabel* label2 = new QLabel(QStringLiteral("Name"));
              QLabel* label3 = new QLabel(QStringLiteral("Name"));
          
              QVBoxLayout* vbox = new QVBoxLayout;
              vbox->addWidget(label2);
              vbox->addWidget(label3);
          
              mLayout->addRow(label1, vbox);
          
              this->setLayout(mLayout);
          

          0_1567504170748_11eddb48-e84d-43bb-86d0-9efb42a914de-image.png

          I would like to have the left label on the same height as the right upper label in the QVBoxLayout.

          Turning on borders:

          0_1567504259014_93b94587-903b-4dfe-a0bf-b9ddfa27876d-image.png

          the label left is stretched for some reason and I can't figure out why.

          Any help would be appreciated!

          GerhardG Offline
          GerhardG Offline
          Gerhard
          wrote on last edited by
          #4

          @leon_2001

          QFormLayout* mLayout = new QFormLayout;

          QLabel* label1 = new QLabel(QStringLiteral("Name"));
          QLabel* label2 = new QLabel(QStringLiteral("Name"));
          QLabel* label3 = new QLabel(QStringLiteral("Name"));
          
          mLayout->addRow(label1, label2);
          mLayout->addRow(new QLabel(""),  label3);
          
          this->setLayout(mLayout);
          

          Gerhard

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Leon_2001
            wrote on last edited by
            #5

            Hi,

            thanks for the suggestion, unfortunately this is not what I want to achieve.
            In your code, there is spacing between label2 and label3. But I want the spacing only between the actual rows. Of course I could work with trickst like an extra Spacing element etc. but that's kinda hacky again.

            Having a QFormLayout combinded with QVBoxLayout is exactly what I need and want (and makes the most sense). I would like to know why it's not working without the code from above, up to now it seems like a bug to me.

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @leon_2001 said in QFormLayout with QVBoxLayout:

              up to now it seems like a bug to me.

              Why? The widget just fills out it's available height and therefore the left widget displays it's text centered. I would take a look at QLabel::alignment

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              L 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @leon_2001 said in QFormLayout with QVBoxLayout:

                up to now it seems like a bug to me.

                Why? The widget just fills out it's available height and therefore the left widget displays it's text centered. I would take a look at QLabel::alignment

                L Offline
                L Offline
                Leon_2001
                wrote on last edited by
                #7

                @christian-ehrlicher

                Which widget? The label on the left side doesn't seeem to fill out the complete avaiable height? Otherwise it would has the same height as the labels on the right together, wouldn't it?

                Why has the left label exactly this height (which by the way stays the same, if you have more spacing in the VBox)

                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