Results 1 to 6 of 6

Thread: automatic coordinate transformation for a data plot in QGraphicsView

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

    Default automatic coordinate transformation for a data plot in QGraphicsView

    Dear all,

    I'm trying to write a simple QWidget class that draws the data in a QPolygonF (=QVector<QPointF>). What I am trying to do is create a QTransform that holds the appropriate coordinate transformation info to transform from a real cartesian coordinate system to the pixel integer coordinate system. The purpose of this is so that I can use from within my QWidget:
    Qt Code:
    1. QPainter p(this);
    2. p.setWorldTransform( QTransform( /*appropriate values*/ ) );
    3. p.drawLine( /*coordinates in real/double values);
    To copy to clipboard, switch view to plain text mode 

    This should be possible, but my calculated transformation does not work as intended .
    I have tried this with following assumption:
    drawLine converts the parameters by multiplying the values with the matrix, which leads to the (rounded off) integer values used to draw the line in the viewed area.
    Then the resize operation would only require adapting the matrix to the new height and width and repainting the scene.

    This does not happen , could someone with more knowledge of QGraphicsview help please. Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: automatic coordinate transformation for a data plot in QGraphicsView

    Could you prepare a minimal compilable example reproducing the problem?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: automatic coordinate transformation for a data plot in QGraphicsView

    Here goes...http://www.mediafire.com/?sharekey=e...eada0a1ae8665a

    I would like to be able to plot a cartesian function, like y=x², by using a QPainter::drawLine( QpointF, QPointF ) and having the transformation between real coordinates and integer coordinates take place within the class, fully automatic through the transformation matrix.

    The transformation formulas I'm using are:
    x' = x/X
    y' = Y - y/Y

    with x' and y' being integer coordinates (with (0,0) being in the topleft corner and the vertical axis downward), x and y being real cartesion coordinates( with (0,0) in the bottomleft corner and the y axis upward), X and Y the integer width and height respectively of the widget (to accommodate resizing and automatic repainting later on).

    The code I uploaded doesn't draw a line from the bottom-left corner right and up. When the matrix isn't set (setWorldTransform is commented out), it of course just draws a silly line, but this is not what I'm trying to accomplish.
    Last edited by rubenvb; 26th September 2009 at 15:30.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: automatic coordinate transformation for a data plot in QGraphicsView

    Quote Originally Posted by rubenvb View Post
    Please use the forum's attachment feature instead of relying on 3rd party sites to link code.

    Well... the "test" project doesn't actually reproduce or describe any problem... From your description it seems that you want a non-linear transformation of physical and logical coordinates. A 3x3 matrix transformation will not allow you to do that.
    Last edited by wysota; 26th September 2009 at 23:55.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: automatic coordinate transformation for a data plot in QGraphicsView

    My bad, sorry. Here it is.
    Attached Files Attached Files

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: automatic coordinate transformation for a data plot in QGraphicsView

    I can only see an empty window in your project.

    BTW. Remember drawLine() takes four integers. If you want to use fraction values, you have to use another variant of drawLine() (like the one that takes a QLineF parameter).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Spectrogram Plot Hints
    By shargath in forum Qwt
    Replies: 2
    Last Post: 25th February 2009, 11:11
  2. Replies: 15
    Last Post: 27th May 2008, 01:46

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.