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. Vertical spacing of items in a QGridLayout
Forum Updated to NodeBB v4.3 + New Features

Vertical spacing of items in a QGridLayout

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

    I'm programming a simple backup utility which will list all the available settings that can be backed up on the main window. As you can see from the screenshot below, if there are not enough checkboxes within the "Personal Data" QGroupBox, the spacing between them is large. Therefore the look of the layout is messing. I'm using a QGridLayout in each of the two QGroupBoxes to place the checkboxes.

    Does anyone have any suggestions of how I could make the spacing the same as the spacing used in the "Application Settings" QGroupBox?

    !http://oi47.tinypic.com/2j3s7bm.jpg!

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      You could use a vertical spacer below the 2 checkboxes.

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lin-unix
        wrote on last edited by
        #3

        Sounds like a good idea but when I try to use a QSpacerItem, it has no effect.

        I create the QGridLayout and checkboxes. Place the two checkboxes. Then create the QSpacerItem and place it into the layout like this:

        @QSpacerItem *vSpacer = new QSpacerItem(100, 100, QSizePolicy::Ignored, QSizePolicy::Ignored);
        m_personalGridLayout->addItem(vSpacer, 3, 0, -1, -1);@

        I use QSizePolicy::Ignored because that way the spacer "will get as much space as possible":http://qt-project.org/doc/qt-4.8/qsizepolicy.html#Policy-enum, but MinimumExpanding and Expanding should do as well. Unfortunately, all three enum values fail in changing anything.

        The QSpacerItem's preferred width and height are set to 100 because I have no preferred width and height - as long as the spacer fills up the space. I tried 1x1 but that didn't help.

        When adding the QSpacerItem to the layout I specify that the spacer can "expand horizontally and vertically":http://qt-project.org/doc/qt-4.8/qgridlayout.html#addItem. Sort of redundant.

        I know I must be missing something or something is overriding the QSpacerItem. Any ideas?

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          I was not clear enough, but i would use a spacer below the gridlayout, not in it;)

          Also i'm used to test layouts in a ui. Afterwards then you can have a look at the code in the generated ...ui.h file.

          Qt Certified Specialist
          www.edalsolutions.be

          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