Results 1 to 4 of 4

Thread: Handle Spacing on Gridlayout with hidden elements

  1. #1
    Join Date
    Mar 2017
    Posts
    9
    Thanks
    3

    Default Handle Spacing on Gridlayout with hidden elements

    Hello,

    I am using a GridLayout (QT 4.8.7) and on certain actions i hide/show parts inside this layout using .hide()/.show().



    The Problem which now occurs is that the spacing of these hidden elements is still shown inside the layout (see picture).

    Screenshot 2017-08-18 09.47.26.png
    Qt Code:
    1. layout = new QGridLayout( this );
    2. layout->setMargin( 1 );
    3. layout->setSpacing( 1 );
    4.  
    5. setSizePolicy( sizePolicy().horizontalPolicy(), QSizePolicy::Fixed );
    To copy to clipboard, switch view to plain text mode 

    Is there a simple way to prevent this behaviour?
    Last edited by PeterSilie; 18th August 2017 at 09:35.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Handle Spacing on Gridlayout with hidden elements

    This is controlled by several settings. First is horizontalSpacing(), then columnMinimumWidth(), and possibly columnStretch(). You may also need to play with the minimumSize() of the widgets you put in the column that become hidden.
    <=== 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.

  3. #3
    Join Date
    Mar 2017
    Posts
    9
    Thanks
    3

    Default Re: Handle Spacing on Gridlayout with hidden elements

    Well,

    it is the vertical spacing.

    Is there any way to set the vertical spacing in the gridlayout for a specific row?

    Cause i'd like to keep the spacing on the shown rows but remove it from the hidden ones.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Handle Spacing on Gridlayout with hidden elements

    Maybe you need a different strategy. If the relationship between the "certain actions" and the rows / columns that are hidden or shown in the view is well-defined (e.g., for action "X", rows 1 - 3 are always hidden, for action "Y", they are always shown) then you might be better off using different widgets laid out specifically for each action and putting them into a QStackedWidget or QStackedLayout and showing whichever one is appropriate. Each widget in the stack contains only that which is needed for the purpose.
    <=== 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.

Similar Threads

  1. Replies: 8
    Last Post: 8th December 2016, 23:03
  2. Replies: 2
    Last Post: 2nd May 2016, 07:56
  3. How to clear the GridLayout
    By rahulgogoi in forum Qt Programming
    Replies: 7
    Last Post: 13th May 2011, 06:22
  4. QMdiArea with Gridlayout
    By ericV in forum Qt Programming
    Replies: 0
    Last Post: 14th September 2009, 11:26
  5. does gridlayout really lay out?
    By illuzioner in forum Newbie
    Replies: 2
    Last Post: 26th February 2006, 00:57

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.