+ Reply to Thread
Results 1 to 2 of 2

Thread: QGridLayout vertical spacing

  1. #1
    Join Date
    Dec 2016
    Posts
    37
    Qt products
    Qt5
    Platforms
    Windows

    Default QGridLayout vertical spacing

    Hi all.

    I create a QGridLayout programatically and then add various widgets to it in the zeroth column of the first few rows.
    This looks fine except that there is a lot of space between widgets/rows when I run the app.
    I've added a vertical spacer in the last row, which does push things up. (Desired behavior.)
    I've tried using setContentMargins and setSpacing with no luck.

    Any ideas?

    Thanks in advance.

    n

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,699
    Thanks
    212
    Thanked 566 Times in 556 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QGridLayout vertical spacing

    I've added a vertical spacer in the last row, which does push things up. (Desired behavior.)
    OK then, if that's what you want, what's wrong with that? If you were using Qt Designer to lay out the grid statically, you would do exactly the same.

    Setting margins and spacing only establish minimums. When you make the container larger, the grid will add more space between rows and columns to fit the larger space. The only way to to constrain the grid to the preferred sizes of its widgets plus spacing is to use a spacer.

    By the way, setContentsMargins() has no effect on the spacing around the widgets in the grid (except with respect to laying out the whole grid). It establishes the margin around the entire grid layout within its parent.
    Last edited by d_stranz; 12th January 2018 at 21:27.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

+ Reply to Thread

Similar Threads

  1. Spacing between QListWidgetItems
    By DavidLinSuperstar in forum Newbie
    Replies: 1
    Last Post: 26th September 2014, 18:08
  2. What is the line spacing
    By smoozer in forum Qt Programming
    Replies: 3
    Last Post: 9th September 2009, 16:26
  3. Problem with spacing
    By ali22 in forum Qt Tools
    Replies: 1
    Last Post: 21st January 2008, 17:51
  4. Delete a QGridLayout and New QGridLayout at runtime
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 5th November 2007, 13:01
  5. Dynamically resize spacing
    By trskel in forum Qt Programming
    Replies: 6
    Last Post: 28th September 2007, 11:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts