PDA

View Full Version : QGraphicsView transformations and resizing



rubenvb
11th December 2009, 19:59
Hi all,

I'm very aware of the existence of Qwt and such, but I am (educationally and more) trying to create my own plotting code in Qt (for now it's an app, easy to debug, later it would be a library much like QtGui and such... that's the idea :D).

Currently I'm struggling with QTransform and setSceneRect and resizing stuff...
1) I would like my plot to resize and fit in the window/widget. Currently I have set the sceneRect to a square between 0 and 100 and drawn a grid on it that shows the borders and the 20-40-60-80 lines. When you resize this , the grid assumes the widget's smallest dimension, which is quite logical seeing the resize function I implemented. I would, however, like the grid to fill the whole QGraphicsView/Scene (which is it?) and "stretch" the spacing of the lines accordingly.
2) After step one is complete: I know there is a setCosmetic that keeps width and all constant. Is this usable for my axes and axes labels and legend, so that their position is scaled, but their shape is not?

Thanks a bunch, I've been struggling with this a lot!
PS: I've attached the source code and 64-bit windows debug binary. As of this moment I get a link.exe crash so it could be there's a small typo-ish bug in the code at the moment. Sorry for that.

rubenvb
11th December 2009, 20:39
I'm extremely sorry to answer my own thread, but this solves point number 1:

void QPlot::resizeEvent( QResizeEvent *event )
{
fitInView( scene->sceneRect(), Qt::IgnoreAspectRatio );
}

I had set Qt::KeepAspectRatio which is quite honestly, pretty stupid for what I wanted to do :)

This stretches the grid like I want it to. It does raise another question though:
3) I'd like to add lines (QPath and QpolygonF stuff) in a manner that QTransform handles all the whole coordinate transformation. I could then just read data from say, a QVector, and say scene->addLine( --points from vector-- ), without having to map the real-world coordinates to current device coordinates. QTransform even has a built-in quadtoQuad function, which I think can accomplish my goal. The problem? Even when I manually modify the QRectF's in quadToQuad, there's no change in the resulting picture :s Why is that?
Thanks again!

rubenvb
15th December 2009, 20:47
bumpedibump...