Quoting a message in the thread referenced by @blueskin:
This is surprisingly difficult to do. Most of the window systems do not
allow the application to set constraints on the window other than the
max and min sizes and that it can be fixed size.
The most common way to attempt this is to call resize from within the resize event. This often causes recursion problems or looks strange because the widget resizes in ways the user has not requested.
Since most window systems do not allow the main window to be resized appropriately, the best solution is often to constrain a child widget rather than the parent. One such way to do this is with a class provided by libqxt.
libqxt has support for keeping a child widget at a certain aspect ratio through its QxtLetterBoxWidget. @blueskin's answer provides one good attempt at doing what was originally requested.
If you're interested I'd recommend you read the source for the resizeWidget()
function and observe the places in which it gets called. As background, libqxt uses the pimpl idiom and qxt_d()
gets at the private member.