PDA

View Full Version : postponing resize event



Honestmath
20th February 2006, 23:05
Good evening to all,

I have widget A whose size and attributes depend on widget B. When a resize event occurs, A and B both resize, but A needs B to resize first so it can grab some relevant parameters. If, within A's resize event, I issue a resize event for B, then I'm afraid that B will end up with 2 resize events. Very inefficient.

Is there a way to make A's resize wait for B's resize to finish?

Cheers,
Math

jacek
20th February 2006, 23:27
Is there a way to make A's resize wait for B's resize to finishNo, because you would wait forever (you have only one thread). You can only try to ensure that A is resized after B.

What is the exact relation between A and B? Are they top-level widgets? Do you use layouts?

wysota
20th February 2006, 23:42
If, within A's resize event, I issue a resize event for B, then I'm afraid that B will end up with 2 resize events. Very inefficient.

Resize event is not that expensive. Especially if it makes a window smaller -- no repaint is needed then. But even with resizing upwards only the part of the window which wasn't visible before needs to be repainted. Provided that repainting is done properly, it should be a cheap operation.

Honestmath
21st February 2006, 00:44
No, because you would wait forever (you have only one thread). You can only try to ensure that A is resized after B.

What is the exact relation between A and B? Are they top-level widgets? Do you use layouts?
Thank you gentlemen for your responses.

A and B are custom widgets consisting of many subwidgets, many of which are also custom widgets. The painting of these custom widgets is fine and not too slow. I have tried to use layouts, but they do not handle the custom widgets properly, nothing is aligned correctly, and there are not enough options in the layouts to cause it to work. Therefore, the resize event must move things manually. I tried to write a custom layout manager, but (as someone in another recent thread experienced) I was unable to make it work.

The resize event for one A widget is not that horrible, but I have several and resizing is noticeable. I am not certain why you say that I "would wait forever" if A waited for B. B would eventually finish and it needs to be resized anyway, I am simply trying to wait until it finishes before A is resized. If I could set the resize order that would be splendid, or if each resize event had a unique ID, but I do not believe either of these scenarios are possible.

Can you suggest another method?

Cheers,
Math

jacek
21st February 2006, 02:00
I have tried to use layouts, but they do not handle the custom widgets properly, nothing is aligned correctly, and there are not enough options in the layouts to cause it to work.
It should work without any problems. Maybe there is something wrong with your custom widgets? Or maybe you need more than one layout?


I am not certain why you say that I "would wait forever" if A waited for B. B would eventually finish and it needs to be resized anyway, I am simply trying to wait until it finishes before A is resized.
The point is that if you wait in a single threaded program, then your program doesn't do anything else. If you block the program flow in widget A, then it will never reach widget B.

Honestmath
21st February 2006, 03:21
It should work without any problems. Maybe there is something wrong with your custom widgets? Or maybe you need more than one layout?


The point is that if you wait in a single threaded program, then your program doesn't do anything else. If you block the program flow in widget A, then it will never reach widget B.
There are no problems with my widgets. I have attached a small form that gives a simple example of why layouts have not worked. It is all about alignment. This example uses only simple built-in widgets, but my widgets get somewhat more complicated, e.g. widget 2 must left align with the center of widget 1, etc. If there is significantly more power and flexibility in the layout managers, I would be delighted to learn of it.

Cheers,
Math

wysota
21st February 2006, 10:46
Is this more or less what you wanted?

jacek
21st February 2006, 12:59
Here's my solution.

Honestmath
24th February 2006, 17:09
Thank you gents for your solutions.

I was away for a bit but returned and played with it a smidgeon. The fixed spacer helps and gets me a mite closer, but I've yet to conquer the beast. The grid layout solution will not work as the checkbox and lineEdit are one widget.

If you desire a challenge, the attached form shows a bit of what I face. Alignment between group boxes is off. Or, on the right, alignment between labels and inputs are off though there are the same number of items in each. The only way I know to address this first problem is to update the minimumSize() of a label in 2 of the 3 boxes to match the size of the longest label in the other box and update it on resizeEvent. I wish I had a better way.

Cheers,
Math

jacek
24th February 2006, 18:51
The grid layout solution will not work as the checkbox and lineEdit are one widget.
That shouldn't be a problem.


The only way I know to address this first problem is to update the minimumSize() of a label in 2 of the 3 boxes to match the size of the longest label in the other box and update it on resizeEvent. I wish I had a better way.
You don't have to do this in resize event. It will be enough if you set it when the length of the longest label changes. Will the text in those labels change?

I've played with it a bit, but it would be a lot easier if those frames were group boxes with a title.

Chicken Blood Machine
24th February 2006, 19:12
Thank you gents for your solutions.

I was away for a bit but returned and played with it a smidgeon. The fixed spacer helps and gets me a mite closer, but I've yet to conquer the beast. The grid layout solution will not work as the checkbox and lineEdit are one widget.
Cheers,
Math

It seems to me that you should just use a vertical boxlayout to group the labels underneath your custom widget.

Then just use the following code on the label to ensure that it is aligned correctly:



#include <qstyle.h>

label->setIndent(style().pixelMetric(QStyle::PM_Indicator Width));

Honestmath
26th February 2006, 00:32
Thank you all. There are still misalignment issues, but I shall continue to try to work out the solutions on these.

Cheers,
Math