Results 1 to 3 of 3

Thread: qgraphicsview and coordinates

  1. #1
    Join Date
    Nov 2009
    Location
    San Antonio, TX
    Posts
    69
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11 Windows
    Thanked 1 Time in 1 Post

    Default qgraphicsview and coordinates

    I am trying to use a qgraphicsview as part of a plotting app. There are two graphs, one above the other that are aligned with the x-axis extents. I have axes around a center widget, in the lower instance it uses a simple qwidget and in upper, it uses a qgraphicsview.

    My problem comes in lining up the axes extents to the extents inside of the qgraphicsview. For example, my X-axis runs from 2000000 to 30000000 and my Y-axis from 3600 to 90000. I call setSceneRect with these values and then call a modified fitInView (modified to remove the hard-coded margin of 2 adjustment). The sceneRect shows the proper (2000000,3600 28000000x86400). However, if I try to do mapToScene( QPoint(0,0) ), I do not get (2000000,3600) that I expect but values slightly off (1971830.985915, 3578.698225), so qgraphicsview does not quite line up with values of the axes. If I put a qgraphicslineitem vertically at 20000000, it does not draw in the proper location wrt x-axis. I know this seems negligible but with a crosshair cursor that displays the x,y values with the cursor position based on the axis, it just looks wrong. And it does not line up with a similar vertical line and similar crosshair cursor in the qwidget that uses transform routines based on the axes.

    Is there a way to tweak the matrix/transform so the qgraphicsview coordinates match closer to my axis scaling?

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3
    Thanked 127 Times in 126 Posts

    Default Re: qgraphicsview and coordinates

    why are you making your own plotting app? there is already qwt.

    btw, it will be your maths/mapping that is making something not quite match. Trying to fudge it with a Qt transform will just move the error somewhere else.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Nov 2009
    Location
    San Antonio, TX
    Posts
    69
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11 Windows
    Thanked 1 Time in 1 Post

    Default Re: qgraphicsview and coordinates

    Quote Originally Posted by amleto View Post
    why are you making your own plotting app? there is already qwt.
    It is an app at work that is unique to the data set.

    btw, it will be your maths/mapping that is making something not quite match. Trying to fudge it with a Qt transform will just move the error somewhere else.
    The qwidget plotting canvas is controlled by the x/y axes . . . simple math to get the mapping. I assumed setting the same x/y ratios in the qgraphicsview would use the same scaling. I guess the fit in view is not producing the affect I expect. The initial setting seems to set the view outside my initial screenRect. How do I set the qgraphicsview to a specific X,Y WxH? Specific meaning that the viewport (0,0) = X,Y and viewport (xmax,ymax) = X+W,Y+H

    I know that pixel on the screen can take on a number of values depending on the resolution of the widget. I just want to be able to specific what those "real" values are for the left,right and top,bottom edges of the qgraphicsview like I do with the qwidget.

Similar Threads

  1. Replies: 5
    Last Post: 3rd March 2016, 16:42
  2. Replies: 2
    Last Post: 29th March 2013, 04:50
  3. how to get mouse coordinates from Qgraphicsview
    By ready in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2011, 06:33
  4. QGraphicsView coordinates system problem
    By Oximoron in forum Newbie
    Replies: 1
    Last Post: 27th April 2010, 17:26
  5. QGraphicsView coordinates transformation
    By mtribaldos in forum Newbie
    Replies: 1
    Last Post: 6th February 2008, 18:44

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
  •  
Qt is a trademark of The Qt Company.