[Qt-interest] aspect-ratio for graphs
phil prentice
philp.cheer at talktalk.net
Thu Jul 15 19:20:53 CEST 2010
Hi Sean
With your help I am now closer to what I would like. I think that part of
my problem was the wish that the frame would always have an aspect ratio of
1:1. This mechanism does not achieve this. If you take your example you can
obviously squeeze the vertical height to make the frames no longer square, I
was half hoping that by some magic the horizontal width could also be made to
reduce, but I think that asking to much (or is it?).
Anyway I guess it would be nice to be able to set the min-height of the main
window to ensure that you cannot squeeze the height to the point of
destroying the aspect ratio. I tried re-implementing the sizeHint() function
for the frame but that did not help.
Should I try catching the resize event (have not looked at this yet) and see
if I can stop the main window from being resized to far using that method?
My other problem is that depending on the mode I need to display either 6
graphs across the screen or just 3.
Thanks again for your help..I will keep playing
Phil
On Thursday 15 July 2010 12:30, phil prentice wrote:
> Thanks
> Sean
> Thats brilliant I will try it now. Please ignore my last post...I will plug
> this into my example!!!!
> Thanks very much for your time
>
> Phil
>
> On Thursday 15 July 2010 11:44, Sean Harmer wrote:
> > On Thursday 15 July 2010 11:55:15 phil prentice wrote:
> > > Sorry Sean
> > > Finger/Brain trouble...
> >
> > No worries.
> >
> > > Indeed I am trying to use heightForWidth()...See my original mail
> > > which has a derived object within a layout. I am cutting it down
> > > though and will continue to try and get it to work. If no success I
> > > will mail the cut down version of my code. If I am successful I will
> > > also provide the code. Thanks for your help
> >
> > OK I have got an example of how to do this for you - see attached
> > tarball.
> >
> > The key is to set a suitable size policy in your custom widget (be it
> > derived from QWidget or from QGraphicsView) and to implement the int
> > heightForWidth( int w ) function.
> >
> > In the attached example I derived a class FixedAspectWidget from QWidget.
> > The ctor and heightForWidth() functions look like this:
> >
> > FixedAspectWidget::FixedAspectWidget(QWidget *parent) :
> > QFrame(parent)
> > {
> > setMinimumSize( 100, 100 );
> > QSizePolicy policy( QSizePolicy::Preferred, QSizePolicy::Minimum );
> > policy.setHeightForWidth( true );
> > setSizePolicy( policy );
> > }
> >
> > int FixedAspectWidget::heightForWidth(int w) const
> > {
> > return w;
> > }
> >
> > That is you have to call QSizePolicy::setHeightForWidth( true ). This
> > then tells any layout into which you place your widget that the layout
> > needs to call your widget's heightForWidth() function which in this case
> > simply returns the input width resulting in a square widget.
> >
> > This of course only provides you with a widget of fixed aspect ratio,
> > drawing your graphs with a fixed aspect ratio is a whole other problem
> > when you consider axis labels, ticks, titles, different coordinate
> > systems etc.
> >
> > HTH,
> >
> > Sean
> >
> > > Phil
> > >
> > > On Thursday 15 July 2010 10:34, you wrote:
> > > > Hi Phil,
> > > >
> > > > please reply to the list not to me personally.
> > > >
> > > > On Thursday 15 July 2010 11:22:10 phil prentice wrote:
> > > > > Thanks Sean
> > > > >
> > > > > Will it help me with my aspect-ratio problem....because if it
> > > > > does then
> > > > >
> > > > > I would definitely use it. Its the aspect-ratio problem I would
> > > > > like to solve...I need my graphs to have aspect-ratio of 1:1(inside
> > > > > a layout). I could not see how QGraphicsView can help me there???
> > > > > Please tell me that I am wrong!!!
> > > >
> > > > QGraphicsView itself is just a QWidget so it will not support fixed
> > > > aspect ratio of the widget itself out of the box - you'll still need
> > > > to use something like heightForWidth() to implement that.
> > > >
> > > > You can make the graphs within your scene fixed aspect ratio quite
> > > > easily though. Can you provide a .ui file that shows the kind of
> > > > layout you would like?
> > > >
> > > > > I am still trying to play, but as of yet not getting anywhere
> > > >
> > > > I have no time to look at this right now but I may be able to later.
> > > >
> > > > Cheers,
> > > >
> > > > Sean
> > >
> > > _______________________________________________
> > > Qt-interest mailing list
> > > Qt-interest at trolltech.com
> > > http://lists.trolltech.com/mailman/listinfo/qt-interest
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list