Results 1 to 4 of 4

Thread: Infinite loop - resize parent from child

  1. #1
    Join Date
    Jan 2006
    Posts
    70
    Thanks
    13
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Infinite loop - resize parent from child

    For this project i'm using Windows and Qt 4.1.2

    I have a QMainWindow that contains a widget that occupies the entire window. When the resizeEvent of the child widget is called I want the child to maintain proportions. After fixing the width/height proportions of the child I need to resize the parent.

    I've included a complete program that demonstrates the issue.

    Here is the wrong solution, but what would be a good workaround for it?

    Qt Code:
    1. void MyWidget::resizeEvent(QResizeEvent* event)
    2. {
    3. QSize newsz = event->size();
    4.  
    5. _figureHeight = newsz.width()*_figureHeight/_figureWidth;
    6. _figureWidth = newsz.width();
    7.  
    8. parentWidget()->resize(_figureWidth, _figureHeight);
    9. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files

  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: Infinite loop - resize parent from child

    Here's your fish
    Qt Code:
    1. void MyWidget::resizeEvent( QResizeEvent *event )
    2. {
    3. const QSize size( event->size() );
    4. const int height = size.height();
    5. const int width = size.widgth();
    6. if( ratioW * height == ratioH * width ) {
    7. QWidget::resizeEvent( event );
    8. }
    9. else {
    10. parentWidget()->resize( width, (ratioH * width) / ratioW );
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    Although it will probably cease to work if you add a menu, status bar or toolbar to your main window.

  3. The following user says thank you to jacek for this useful post:

    bitChanger (5th May 2006)

  4. #3
    Join Date
    Jan 2006
    Posts
    70
    Thanks
    13
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Infinite loop - resize parent from child

    Thank you.

    I beleive that line 10 does not have to be divided by ratioW though.
    Changing line 10 to the following seems right to me ??

    Qt Code:
    1. parentWidget()->resize( width, ratioH * width);
    To copy to clipboard, switch view to plain text mode 

  5. #4
    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: Infinite loop - resize parent from child

    Quote Originally Posted by bitChanger
    I beleive that line 10 does not have to be divided by ratioW though.
    Changing line 10 to the following seems right to me ??
    It depends. In above code ratioW and ratioH can be integers. You can use doubles and then one of there variables can be 1.0 and thus omitted.

Similar Threads

  1. connecting child to parent window...
    By sumit in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2008, 22:28
  2. How to close parent window from child window?
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 14th October 2008, 12:40
  3. Move child widget along with the parent widget
    By sreedhar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2006, 13:00
  4. Referencing Parent Widget from Child
    By taylor34 in forum Qt Programming
    Replies: 8
    Last Post: 11th April 2006, 16:13

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.