Results 1 to 2 of 2

Thread: QMainWindow resize with correct aspect ratio

  1. #1
    Join Date
    Oct 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QMainWindow resize with correct aspect ratio

    I have been struggling quite a lot on this, there seems to be no way to let user resize a top level QMainWindow mantaining the same aspect ratio, I found lot's of posts about this on the net but no one seem to have a working answer.


    Thank you

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QMainWindow resize with correct aspect ratio

    So rather than try to control something which is probably under the control of the platform's windowing system (and thus out of your control), change the behaviour of the central widget in the QMainWindow. This probably means you will have to implement a custom "wrapper" widget to serve as the central widget, and make your original central widget a child of this. QMainWindow will automatically resize your wrapper widget to occupy all of the space available. However, this wrapper can make its child widget any size and put it any place it wants to. So the resizeEvent for the wrapper widget needs to compute the maximum size for your fixed aspect widget given the new size of the wrapper, and then resize and position the fixed aspect widget appropriately. You probably will need to implement the paint event for the wrapper widget so you can fill the empty background with whatever color you like.

Similar Threads

  1. Get aspect ratio from Phonon videoWidget
    By budda in forum Qt Programming
    Replies: 2
    Last Post: 24th October 2012, 08:46
  2. Replies: 0
    Last Post: 21st November 2011, 07:55
  3. Printing and Aspect ratio
    By cpt4 in forum Qwt
    Replies: 9
    Last Post: 30th September 2011, 14:28
  4. How to get aspect ratio on selection with rubberBand?
    By suseway in forum Qt Programming
    Replies: 6
    Last Post: 25th October 2010, 08:29
  5. Preserving aspect ratio of image
    By Banjo in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2009, 13:39

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.