PDA

View Full Version : How to resize parent widget when child widget is resized



ainne810329
22nd November 2011, 09:33
Does anyone know how I can trigger the parent to resize when its child widget is resized?

What I have tried is that emit signal in the resizeevent of the child widget and do the slot of the parent widget to resize the parent.
But unfortunately resizing the parent will cause the child widget to be resized again. So in this way, I get a loop and it doesn't give
me the result that I expect.

Can somebody help with that?

qlands
23rd November 2011, 13:30
Hi,

If you are using layouts it might happen that resizing the parent will re-size its children.

I am trying to imagine what are you trying to do? How are you resizing the child, with the mouse or by code? What king of widget it is?

Instead of just resizing the parent, you might need to write some code to separate the re-sizes that happens because of the change in size of the parent from the ones made in the child by your code or mouse. In short, to emit your signal only for just some cases.

Carlos.

MarekR22
23rd November 2011, 13:39
I suspect that you should read about sizeHint for classic widgets or QGraphicsWidgets.

I did something nasty with that (resizing text label on line wrapping) so if you explain you initial problem (not how you are trying to solve it) then I may be able to help.

ChrisW67
23rd November 2011, 22:59
It really depends what you are trying to achieve. There is an example of automatically resizing a dialog when an optional child panel is requested. It uses size policy to achieve this.

If you are programatically changing the size of a child widget to hold some new data/image/whatever then you may be able to force the parent to grow using the minimum size attribute of the child.

Generally, I consider arbitrarily resizing main windows bad form.

ainne810329
29th November 2011, 07:47
Thank you for the replies so far.

My initial problem is that I add a QTableWidget in a window, the content of the table widget is filled in later. When it is filled in, I call resizeColumnsToContents() to resize the table widget, and that works
perfectly. But then my window doesn't resize itself so I get window with only part of the table widget visualized. I want to have the window also to be resized so I can have a complete view.