Page 1 of 2 12 LastLast
Results 1 to 20 of 32

Thread: Problem in layout widgets in a grid

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem in layout widgets in a grid

    Hi to all,
    layouts don't want enter in my mind.
    I would layout 4 widgets in a grid ( 2 x 2 ), 2 QLabels and 2 QLeds.
    I have some problems with the space between widgets and w and h of the layout.
    I attach a screenshot layout.jpg.
    Basically I layout some buttons horizontally having an height, then I add the gridlayout to the horizontally layout. The problem is that the height of the grid is bigger that the height of the buttons and is not what I would achieve. I would the gridlayout to be height as the buttons and also the horizontal space between widget is too big.
    I tried with setHorizontalSpacing, setSpacing without success.
    What can I do?
    Regards
    Franco Amato

  2. #2
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in layout widgets in a grid

    any reply please?
    Franco Amato

  3. #3
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in layout widgets in a grid

    Well seems an unsolvable problem .
    I hope to get a reply.
    Best
    Franco Amato

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem in layout widgets in a grid

    Two rows of labels with this font are larger than the button. If you want them to fit, you need to decrease their size (and possibly the size of the other two widgets as well). You can also manipulate the spacing and margins of the layout but it won't do much without decreasing sizes of the widgets that are part of the layout.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in layout widgets in a grid

    Quote Originally Posted by wysota View Post
    Two rows of labels with this font are larger than the button. If you want them to fit, you need to decrease their size (and possibly the size of the other two widgets as well). You can also manipulate the spacing and margins of the layout but it won't do much without decreasing sizes of the widgets that are part of the layout.
    Hi Wysota,
    I followed your suggestion and moved the grid layout on the left but I still have a space that I can not remove.
    I attach this screenshot spaces.jpg showing the space I would remove.

    I post some code:

    Qt Code:
    1. m_focusLed = new QLed(this); // I create a QLed
    2. m_focusLed->setFixedSize(13,13);// set its size to 13, 13
    3. m_encodingLed = new QLed(this); // the same for the other led
    4. m_encodingLed->setFixedSize(13,13);
    5.  
    6. QLabel* activeLabel = new QLabel(tr("A")); // create a QLabel
    7. activeLabel->setFixedSize(13,10); // set the size
    8. QLabel* encodingLabel = new QLabel(tr("E"));
    9. encodingLabel->setFixedSize(13, 10);
    10.  
    11. QGridLayout* gl = new QGridLayout(); // create the grid and add the widgets
    12. gl->setAlignment(Qt::AlignLeft);
    13. gl->setContentsMargins(0, 0, 0, 0);
    14. gl->addWidget(activeLabel, 0, 0);
    15. gl->addWidget(m_focusLed, 0, 1);
    16. gl->addWidget(encodingLabel, 1, 0);
    17. gl->addWidget(m_encodingLed, 1, 1);
    To copy to clipboard, switch view to plain text mode 

    then I insert the grid layout in horizontal layout so:

    Qt Code:
    1. /* main layout */
    2. lo->setSpacing(0);
    3. lo->addLayout(gl); // <--add the grid layout
    4. /* add more widgets ( buttons ) */
    5. //...
    To copy to clipboard, switch view to plain text mode 

    Doing so I got such space and I would delete it.
    I hope yo get help.

    Best Regards
    Franco Amato

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem in layout widgets in a grid

    I did not suggest to move the layout anywhere.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in layout widgets in a grid

    Quote Originally Posted by wysota View Post
    I did not suggest to move the layout anywhere.
    Yes I know, you suggested to me to decrease the size, and I did it. I did what you suggested AND I moved the layout on the left size
    Franco Amato

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem in layout widgets in a grid

    I don't see where exactly you decreased the font size. And your two leds plus the spacing between them are surely larger than the button that determines the height of the row.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in layout widgets in a grid

    Quote Originally Posted by wysota View Post
    I don't see where exactly you decreased the font size. And your two leds plus the spacing between them are surely larger than the button that determines the height of the row.
    Hi Wysota,
    the space I would remove is the horizontal space as indicated in the last screenshot I attached. It's located on the right of the leds.
    Franco Amato

  10. #10
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in layout widgets in a grid

    Quote Originally Posted by franco.amato View Post
    Hi Wysota,
    the space I would remove is the horizontal space as indicated in the last screenshot I attached. It's located on the right of the leds.
    So how can I remove such space?
    regards
    Franco Amato

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem in layout widgets in a grid

    I have no idea what you want. You show pictures with some things and write about other things.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in layout widgets in a grid

    Quote Originally Posted by wysota View Post
    I have no idea what you want. You show pictures with some things and write about other things.
    Wysota the last screenshot I attached show the problem.
    I attach it again spaces.jpg

    Regards
    Franco Amato

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem in layout widgets in a grid

    Is the space caused by the layout or by the widgets in the layout?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #14
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in layout widgets in a grid

    Quote Originally Posted by wysota View Post
    Is the space caused by the layout or by the widgets in the layout?
    Wysota I think by the layout, as I set the size of the widgets in the layout
    Franco Amato

  15. #15
    Join Date
    Nov 2010
    Posts
    97
    Thanks
    6
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem in layout widgets in a grid

    ...the horizontal space between widget is too big.
    I tried with setHorizontalSpacing, setSpacing without success.
    I'm new to Qt so don't know how Qt does it, but every reasonably expressive UI API and sizer system allows you to tell an area within the sizer not to grow. I can't be sure, but my bet is that your grid is being expanded to fill the space given to it by the sizer it is within. You may need to tell THAT sizer that it shouldn't be giving any free space to your grid (or you might have to tell the grid not to take any, depending on how Qt does it). Then the space should be absorbed by a different widget.

    Simply setting the size may very well be insufficient for this need. Sizers/layouts/whatever tend to give out space according to how THEY have been told to, letting the widgets given that space to resize as they desire, and then *positioning them within the space given* according to whatever rules have been dictated/defaulted.

    It's just a guess, but it's a reasonable one and you're not getting any other answers...so there you go...

    BTW, I tend to get quicker, better, possibly ANY answers at stackoverflow.com

  16. #16
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in layout widgets in a grid

    Quote Originally Posted by nroberts View Post
    I'm new to Qt so don't know how Qt does it, but every reasonably expressive UI API and sizer system allows you to tell an area within the sizer not to grow. I can't be sure, but my bet is that your grid is being expanded to fill the space given to it by the sizer it is within. You may need to tell THAT sizer that it shouldn't be giving any free space to your grid (or you might have to tell the grid not to take any, depending on how Qt does it). Then the space should be absorbed by a different widget.

    Simply setting the size may very well be insufficient for this need. Sizers/layouts/whatever tend to give out space according to how THEY have been told to, letting the widgets given that space to resize as they desire, and then *positioning them within the space given* according to whatever rules have been dictated/defaulted.

    It's just a guess, but it's a reasonable one and you're not getting any other answers...so there you go...

    BTW, I tend to get quicker, better, possibly ANY answers at stackoverflow.com
    Hi,
    I think you're right but I have no idea on how to tell to the grid to don't get such space
    Franco Amato

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem in layout widgets in a grid

    Quote Originally Posted by franco.amato View Post
    Wysota I think by the layout, as I set the size of the widgets in the layout
    Don't think. Check it out. See what size the widget wants to have and what size it indeed has.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  18. #18
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in layout widgets in a grid

    Quote Originally Posted by wysota View Post
    Don't think. Check it out. See what size the widget wants to have and what size it indeed has.
    I wrote this code:

    Qt Code:
    1. m_focusLed = new QLed();
    2. m_focusLed->setFixedSize(13,13);
    3. m_focusLed->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    4. QSize size = m_focusLed->sizeHint();
    5. qDebug() << size.width() << " " << size.height();
    To copy to clipboard, switch view to plain text mode 

    And the result was -1 -1
    Franco Amato

  19. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem in layout widgets in a grid

    Too bad
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  20. #20
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in layout widgets in a grid

    Quote Originally Posted by wysota View Post
    Too bad
    Too bad my code or the result?

    I reimplemented the sizeHint method for the QLed so:

    Qt Code:
    1. QSize QLed::sizeHint() const
    2. {
    3. return QSize(15, 15);
    4. }
    To copy to clipboard, switch view to plain text mode 

    But the space is still there so seems is a layout problem that definitively I don't know how to solve
    Last edited by franco.amato; 23rd November 2010 at 20:55.
    Franco Amato

Similar Threads

  1. Replies: 8
    Last Post: 5th May 2021, 16:41
  2. Grid Layout problem
    By succorguy in forum Qt Programming
    Replies: 1
    Last Post: 26th April 2009, 23:01
  3. How do I layout in a Grid?
    By DPinLV in forum Qt Tools
    Replies: 7
    Last Post: 10th August 2006, 01:37
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  5. Grid layout
    By nupul in forum Qt Programming
    Replies: 7
    Last Post: 21st April 2006, 21:15

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.