Whenever you need a heightForWidth(), you're doing it wrong. Now, I've thought 
I needed the same thing, but you only need that when you're trying to maintain 
an aspect ratio. It is very simple to write your own QWidget subclass, but 
realize you don't want to really modify the height, you just want to know it to 
maintain the aspect ratio. You'll figure this out when you code a proper one. 
:-)

Or, libQxt has as "LetterBox" widget that will parent the widget and do what 
you want. 





________________________________
 From: John Weeks <j...@wavemetrics.com>
To: "Interest@qt-project.org Interest" <interest@qt-project.org> 
Sent: Thursday, March 6, 2014 7:59 PM
Subject: [Interest] heightForWidth
 

I have a need for windows that maintain a set aspect ratio, so I implemented 
heightForWidth(). Since I'm still exploring, I made it very simple (this 
function is called by a wrapper class that actually implements 
heightForWidth()):

int grafRec::doHeightForWidth(int w)
{
    return w/2;
}

I set a size policy:

        QSizePolicy policy(QSizePolicy::Preferred, QSizePolicy::Preferred);
        policy.setHeightForWidth(true);
        content->setSizePolicy(policy);

The object called "content" is a subclass of QWidget and it is embedded in a 
cell of a QGridLayout. There are no other cells in the layout occupied. The 
layout and managed content widget are embedded in a top-level widget.

This actually works up to a point. As I make the window get wider, it also gets 
taller in proportion. But evidently Qt is enforcing a height that is *at least* 
half the width, where I really need a height that is *exactly* half the width.

Is this working as expected, that the height returned by heightForWidth() is 
really a minimum height? If that is so, is there a way to achieve what I really 
want?

Thank you all!

-John Weeks

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to