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. [SOLVED] How to set Multiple QGroupBox alignment in QVBoxLayout
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How to set Multiple QGroupBox alignment in QVBoxLayout

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.1k 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.
  • K Offline
    K Offline
    kloveridge
    wrote on last edited by
    #1

    This is a seemingly basic issue. But I am having difficultly getting exactly what I want. I have a QVBoxLayout that I want to stack multiple QGroupBox widgets into. I want them to align from top to bottom and stay connected together. This is what happens by default:
    !http://i.imgur.com/JZbYaRC.png()!

    I have tried several alignment settings. This will work, but is this the right way?

    @ ui->NodeView->addWidget(m_nodeTransform);
    ui->NodeView->addWidget(m_nodeCommon);

    ui->NodeView->setAlignment(m_nodeCommon, Qt::AlignTop);@
    
    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi,
      The empty space needs to be filled by something. Use a Vertical spacer below the last QGroupbox and your fine. OTherwise the layout will try to fill the available space with the widgets it has (the two groupboxes)

      Greetz, Jeroen

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kloveridge
        wrote on last edited by
        #3

        That worked. Thank you!

        Here's a snippet of code that did it.

        @QSpacerItem* spacer = new QSpacerItem(300,1000, QSizePolicy::Expanding, QSizePolicy::Expanding);
        spacer->setAlignment(Qt::AlignVCenter);

        ui->NodeView->addWidget(m_nodeTransform);
        ui->NodeView->addWidget(m_nodeCommon);
        ui->NodeView->addWidget(m_nodeDrawable);
        ui->NodeView->addItem(spacer);@

        1 Reply Last reply
        0
        • JeroentjehomeJ Offline
          JeroentjehomeJ Offline
          Jeroentjehome
          wrote on last edited by
          #4

          Oke, glad it helped!
          Here is some docs for you to solve other issues with layouts:
          "LayoutManagement":http://qt-project.org/doc/qt-5/layout.html
          Also, the use of addItem is not wrong, but it might be better to use this:
          @
          void QBoxLayout::addSpacerItem(QSpacerItem * spacerItem)
          @
          This is more appropriate.

          Greetz, Jeroen

          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