[Interest] heightForWidth
Jason H
scorp1us at yahoo.com
Fri Mar 7 22:24:55 CET 2014
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 <john at wavemetrics.com>
To: "Interest at qt-project.org Interest" <interest at 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 at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140307/8e2c6394/attachment.html>
More information about the Interest
mailing list