Results 1 to 16 of 16

Thread: QT GraphicsView Help

  1. #1
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default QT GraphicsView Help

    Hi,

    I am an undergraduate developing a simple GUI for plotting curves. I have previously developed the program successfully using Qwt, however I would like to use Qt's GraphicsView to plot the data. However, I have no references on the matter. Or simple examples to learn from. I have read the article, http://doc.trolltech.com/4.2/graphicsview.html, and am still confused on implementing GraphicsView.

    Do I need to use this with QPainter? I am utterly lost. Would anyone be able to help me produce a simple example plotting a line graph using GraphicsView? All I need is something simple to get me started. Or if anyone could point me in the direction of a simple example or beginner websites.

    Thanks,
    Anthony

  2. #2
    Join Date
    Oct 2006
    Posts
    60
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QT GraphicsView Help

    You will need to use QGraphicsView with a QGraphicsScene. You add items to the scene; in your case probably a QGraphicsPathItem. I used QGraphicsView to develop a simple strategy football game and added squares, circles, stars, and pictures using the QGraphicsScene. I can post a simple example if you'd like.

    mAx

    EDIT: I attached a simple dialog that displays a star.
    Attached Files Attached Files
    Last edited by maxpower; 8th February 2007 at 19:02. Reason: updated contents

  3. The following user says thank you to maxpower for this useful post:

    mistertoony (12th February 2007)

  4. #3
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: QT GraphicsView Help

    hey thank you so much. i briefly looked at the example, and it has already helped my understanding of graphicsscene and graphicsview tremendously. i hope to be able to apply this with plotting. do you believe that this is the best technique to plot 2d data?

  5. #4
    Join Date
    Feb 2007
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT GraphicsView Help

    Hello people !

  6. #5
    Join Date
    Oct 2006
    Posts
    60
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QT GraphicsView Help

    I have not done a whole lot of real 2d plotting, but my first instinct would be that Qwt would be a better fit. I have used it in the past to create bar graphs and it seems to just make it easier to do the things you could do with a QGraphicsScene/View since it is specific to plotting/graphing.

    mAx

  7. #6
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: QT GraphicsView Help

    Quote Originally Posted by maxpower View Post
    I have not done a whole lot of real 2d plotting, but my first instinct would be that Qwt would be a better fit. I have used it in the past to create bar graphs and it seems to just make it easier to do the things you could do with a QGraphicsScene/View since it is specific to plotting/graphing.

    mAx
    i agree completely, however we are having trouble getting qwt to be successfully incorporated into the ms visual studio for windows in our research lab. additionally, i had some trouble creating a qwt plot that I would be able to scroll horizontal because each data set has at least 1000 horizontal X values.

    also, would the QPainterPath lineTo function be the best way to plot multiple data points. because i am still having difficulty, essentially my data is like this:
    (1,3), (2,5), (3,6), (4,10), (5,20).... and so on. there is a corresponding Y value for each incrementing X value.

    the data and plot will resemble, http://www.hgsc.bcm.tmc.edu/download.../trace_viewer/
    Last edited by mistertoony; 12th February 2007 at 17:50.

  8. #7
    Join Date
    Oct 2006
    Posts
    60
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QT GraphicsView Help

    Here is an example that uses QPainterPath's cubicTo function to (I think) display a plot like you envision. I am not sure why there is a line at the bottom of the plot.

    mAx
    Attached Files Attached Files

  9. The following user says thank you to maxpower for this useful post:

    mistertoony (12th February 2007)

  10. #8
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: QT GraphicsView Help

    Quote Originally Posted by maxpower View Post
    I have not done a whole lot of real 2d plotting, but my first instinct would be that Qwt would be a better fit. I have used it in the past to create bar graphs and it seems to just make it easier to do the things you could do with a QGraphicsScene/View since it is specific to plotting/graphing.

    mAx
    hey maxpower,

    i haven't taken a look at the cubic example yet. but have a look at what i did before using QWT, how would i make a plot like this horizontal scroll because the plot only represents a small portion of the total data i would like to plot. rather than 500 X values, i would actually need to plot 10,000.


  11. #9
    Join Date
    Oct 2006
    Posts
    60
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QT GraphicsView Help

    Qt will automatically add a scrollbar if the QGraphicsScene/View is too big for the current window. In your example, you would either want to move your horizontal labels inside the scene so that they get scrolled too, or you would have to subclass the scrollbar so that when it moved your label would change.

    mAx

  12. #10
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: QT GraphicsView Help

    Quote Originally Posted by maxpower View Post
    Qt will automatically add a scrollbar if the QGraphicsScene/View is too big for the current window. In your example, you would either want to move your horizontal labels inside the scene so that they get scrolled too, or you would have to subclass the scrollbar so that when it moved your label would change.

    mAx
    the above example is a QWT plot. when you say that Qt will automatically add a scrollbar in the GraphicsScene/View is too big, did you mean that this was also true for QWT. because the QWT plot appears to stay in a fixed restraints without a scrollbar.

  13. #11
    Join Date
    Oct 2006
    Posts
    60
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QT GraphicsView Help

    I am talking about QGraphicsScene/View. I have no idea about qwt.

    mAx

  14. #12
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QT GraphicsView Help

    Have a look at the realtime example, that is included in the Qwt package. It shows how to add scrollbars to a plot. ( they appear, when you zoom in. ). Guess you can copy and use the ScrollZoomer class, like it is.

    Instead of scrollbars you could also use wheels, what is demonstated in the eventfilter example. Another option for navigation is panning (QwtPlotPanner). The bode example shows how to combine zooming and panning.

    HTH,
    Uwe

  15. #13
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: QT GraphicsView Help

    has anyone done plotting with QPolygonF or QPainterPath? i am having trouble understanding the coordinate system. for instance, if i use the following function:

    void QPainterPath::lineTo ( qreal x, qreal y )

    lineTo(1,4); how does this actually work? because it seems to be upside or something?

  16. #14
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT GraphicsView Help

    did u use moveTo() before lineTo() ??

  17. #15
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: QT GraphicsView Help

    Quote Originally Posted by aamer4yu View Post
    did u use moveTo() before lineTo() ??
    yes i did. does the QGraphicsScene rely on the cartesian coordinate system? because something is really messed up.

  18. #16
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT GraphicsView Help

    may be you are confusing the cordinate systems...
    cartesian systems start from bottom left.... while painting in devices has a cordinate system starting from top left

    i guess u r getting the result upside down on Y axis ??

Similar Threads

  1. GraphicsView rotate problem
    By forrestfsu in forum Qt Programming
    Replies: 7
    Last Post: 21st November 2007, 20:20

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.