PDA

View Full Version : Trouble resizing labels inside groupboxes



Jimbot
30th August 2014, 23:34
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 ---> 10601

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 ----> 10602

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

anda_skoa
31st August 2014, 15:07
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

Jimbot
1st September 2014, 00:58
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?

anda_skoa
1st September 2014, 06:38
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,
_

Jimbot
3rd September 2014, 00:53
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

d_stranz
3rd September 2014, 01:16
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.