Results 1 to 12 of 12

Thread: postponing resize event

  1. #1
    Join Date
    Feb 2006
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Windows

    Default postponing resize event

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: postponing resize event

    Quote Originally Posted by Honestmath
    Is there a way to make A's resize wait for B's resize to finish
    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?

  3. #3
    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: postponing resize event

    Quote Originally Posted by Honestmath
    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.

  4. #4
    Join Date
    Feb 2006
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: postponing resize event

    Quote Originally Posted by jacek
    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

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: postponing resize event

    Quote Originally Posted by Honestmath
    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.

  6. #6
    Join Date
    Feb 2006
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: postponing resize event

    Quote Originally Posted by jacek
    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
    Attached Files Attached Files

  7. #7
    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: postponing resize event

    Is this more or less what you wanted?
    Attached Files Attached Files

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: postponing resize event

    Here's my solution.
    Attached Files Attached Files

  9. #9
    Join Date
    Feb 2006
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: postponing resize event

    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
    Attached Files Attached Files

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: postponing resize event

    Quote Originally Posted by Honestmath
    The grid layout solution will not work as the checkbox and lineEdit are one widget.
    That shouldn't be a problem.

    Quote Originally Posted by Honestmath
    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.
    Attached Files Attached Files

  11. #11
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: postponing resize event

    Quote Originally Posted by Honestmath
    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:

    Qt Code:
    1. #include <qstyle.h>
    2.  
    3. label->setIndent(style().pixelMetric(QStyle::PM_IndicatorWidth));
    To copy to clipboard, switch view to plain text mode 
    Last edited by Chicken Blood Machine; 24th February 2006 at 20:15.
    Save yourself some pain. Learn C++ before learning Qt.

  12. #12
    Join Date
    Feb 2006
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: postponing resize event

    Thank you all. There are still misalignment issues, but I shall continue to try to work out the solutions on these.

    Cheers,
    Math

Similar Threads

  1. Replies: 4
    Last Post: 19th February 2009, 12:10
  2. Resize event on stretch?
    By kodiak in forum Qt Programming
    Replies: 2
    Last Post: 3rd November 2008, 23:51
  3. Qt event queue overloading?
    By gct in forum Qt Programming
    Replies: 3
    Last Post: 17th March 2008, 19:39
  4. The event fired by the mouse click on the frame
    By Placido Currò in forum Qt Programming
    Replies: 8
    Last Post: 3rd March 2007, 10:05
  5. Resize event
    By boss_bhat in forum Qt Programming
    Replies: 5
    Last Post: 19th July 2006, 16:43

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.