Results 1 to 3 of 3

Thread: QGridLayout: force all widget to the same size

  1. #1
    Join Date
    Jan 2011
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGridLayout: force all widget to the same size

    Let's say I want to make a simple layout like this:
    Qt Code:
    1. +----------+----------+----------+
    2. | | | |
    3. | | | |
    4. +----------+----------+----------+
    5. | | | |
    6. | | | |
    7. +----------+----------+----------+
    To copy to clipboard, switch view to plain text mode 
    This is easy enough, however I want all the widgets to always have the same size, i.e. all the widgets within the grid layout should take up the space equally.

    For instance, if I have a setup like this:
    Qt Code:
    1. +----------+----------+
    2. | | |
    3. | QTable |QGLWidget |
    4. | Widget | |
    5. +----------+----------+
    6. | | |
    7. |QGLWidget |QGLWidget |
    8. | | |
    9. +----------+----------+
    To copy to clipboard, switch view to plain text mode 
    the space taken by each widget should be equal. However, in that setup, without doing any size policy changes etc., the table widget will take up the whole space, since its default policy will expand in all directions and the QGLWidgets have 'no content to work against that' so to speak.

    Is there a way to achieve this through size policies or layout settings, without setting the sizes of each widget manually?

  2. #2
    Join Date
    May 2010
    Posts
    61
    Thanks
    2
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QGridLayout: force all widget to the same size

    Hi Spooky,

    Personally, I do not believe that you can achieve what you want only through size policies.
    Basically, when you setup a layout to a Widget, you tell him to occupy all the space available.
    And if your QGLWidgets do not have "any content", then it is expected for the QTableWidget to fill the parent widget.

    One idea to do it would be to get the size of the top widget (the one that contains all the 4 widgets) and to set a maximumSize on the QTableWidget (maximumSize which you can calculate from the top widget's size).

    Again I have to mention that this is only my personal opinion, does anybody else have a different point of view?

    Hope this helps though.

    Regards,
    Wladek
    One second is long, everything longer than two seconds is definitely too long.

  3. #3
    Join Date
    Jan 2011
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGridLayout: force all widget to the same size

    Well, I played around a bit and I now think, that QSplitter fits my needs better. It was just an initial desire, that all widgets, no matter their actual content, should have the same size, if possible, but it's better for the user anyway, if he has the possibility to resize the layout in some way, which I can achieve with QSplitter. I also played around with the stretch factors of my QSplitter setup and managed to get good initial sizes for that particular setup (the one with the table widget on the top left and 3 QGL Widgets).

Similar Threads

  1. how to force an immediate repaint on a widget
    By mortoray in forum Qt Programming
    Replies: 3
    Last Post: 12th October 2010, 17:31
  2. Set size when insert a QWidget into a QGridLayout
    By Tondog in forum Qt Programming
    Replies: 3
    Last Post: 4th June 2010, 06:35
  3. Replies: 1
    Last Post: 12th January 2010, 12:42
  4. Adjusting Widget size in a QGridLayout
    By Max Yaffe in forum Qt Programming
    Replies: 1
    Last Post: 30th July 2007, 22:03
  5. Margin size of QGridLayout
    By Cainofnod in forum Qt Programming
    Replies: 1
    Last Post: 13th January 2007, 08:59

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.