Results 1 to 6 of 6

Thread: Trouble resizing labels inside groupboxes

  1. #1
    Join Date
    Jul 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Trouble resizing labels inside groupboxes

    Hello,

    I'm having trouble using labels and groupboxes when resizing my main window.

    I am trying to make a card game which has the following layout ---> game_screemshot.jpg

    Because I need some cards to overlap I positioned them within groupboxes and then added the groupboxes to layouts. The window is made up of 3 horizontal layouts (top, middle, and bottom rows) which are then added to one vertical layout (which is set as the window layout).

    This is works fine when the window is maximized, but when I resize the window, my card images do not scale with the window ----> resized_game.jpg

    I have subclassed my labels so that they scale images when their resizeEvent is triggered which works fine on its own (ie outside of a groupbox), but when the labels are inside a groupbox, the labels resizeEvents are never called, despite the groupbox resizeEvents being triggered.

    How can I correct this? Is there a way of making my labels inside a groupbox detect when the groupbox is being resized? Or should I be approaching the overall layout problem differently?

    Thanks for any guidance,

    Jimbot

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Trouble resizing labels inside groupboxes

    You probably don't have a layout inside the group boxes, so the groupbox children position and size is not controlled by anything other than your code.
    If you have code that should resize them then there is a bug in there. If not than this is what you are missing.

    Cheers,
    _

    P.S.: have a look at QGraphicView

  3. #3
    Join Date
    Jul 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Trouble resizing labels inside groupboxes

    Thanks for your reply anda_skoa.

    No I don't have layouts inside my groupboxes - will I be able to stack my labels (with images) on top of one another if I use layouts inside the groupboxes? I would expect the layout to control where any widgets are positioned?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Trouble resizing labels inside groupboxes

    Quote Originally Posted by Jimbot View Post
    No I don't have layouts inside my groupboxes - will I be able to stack my labels (with images) on top of one another if I use layouts inside the groupboxes? I would expect the layout to control where any widgets are positioned?
    Yes, that is what layouts do, so not having a layout resulted in the widgets remaining uneffected by the changes around them.

    What you need is your own "layout" management code, something that reacts to changes on the group box and then rearranges/resizes the groupbox children.
    Just like a layout inside the groupbox would, but according to your specific needs.

    Cheers,
    _

  5. #5
    Join Date
    Jul 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Trouble resizing labels inside groupboxes

    Ah ok, I think I understand.

    So you are saying that I need a layout, but none of the 'standard' layouts (horizontal, vertical, grid, etc) will help me, so I need to develop my own equivalent? Is that right?

    Thank you

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,481
    Thanks
    252
    Thanked 711 Times in 701 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Trouble resizing labels inside groupboxes

    I think you'd end up with a lot of overhead trying to implement a QLayout-derived class. It would probably be easier to simply create a custom QWidget class to hold the card widgets, and in its resizeEvent handler resize, move, and stack the card widgets as you wish. You could then dispense with the group boxes and simply use a single vertical layout with three of your custom widgets.

    You could also do this using QGraphicsScene / QGraphicsView / QGraphicsItem rather than using QWidgets.

Similar Threads

  1. Several GroupBoxes with Radiobutton function
    By KeineAhnung in forum Newbie
    Replies: 8
    Last Post: 1st May 2014, 22:37
  2. Resizing labels after setText()
    By stephelton in forum Qt Programming
    Replies: 15
    Last Post: 13th January 2013, 11:41
  3. Trouble with widgets resizing
    By papillon in forum Qt Programming
    Replies: 2
    Last Post: 9th August 2012, 10:47
  4. Trouble resizing QDockWidget buttons with style sheet
    By Jon Heron in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2012, 02:41
  5. Resizing QGraphicsView inside a QGridLayout
    By mckinnon in forum Newbie
    Replies: 3
    Last Post: 9th September 2010, 10: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.