Results 1 to 3 of 3

Thread: QGraphicsView transformations and resizing

  1. #1
    Join Date
    Sep 2009
    Posts
    30
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsView transformations and resizing

    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 ).

    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.
    Attached Files Attached Files

  2. #2
    Join Date
    Sep 2009
    Posts
    30
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView transformations and resizing

    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!

  3. #3
    Join Date
    Sep 2009
    Posts
    30
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView transformations and resizing

    bumpedibump...

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.