PDA

View Full Version : QT GraphicsView Help



mistertoony
8th February 2007, 17:12
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

maxpower
8th February 2007, 18:43
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.

mistertoony
9th February 2007, 17:25
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?

kitov
10th February 2007, 15:40
Hello people !

maxpower
12th February 2007, 15:50
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

mistertoony
12th February 2007, 16:27
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/downloads/software/trace_viewer/

maxpower
12th February 2007, 18:47
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

mistertoony
12th February 2007, 19:23
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.

http://www2.bc.edu/~nguyenah/scf_plot.JPG

maxpower
12th February 2007, 19:52
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

mistertoony
12th February 2007, 19:58
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.

maxpower
12th February 2007, 20:44
I am talking about QGraphicsScene/View. I have no idea about qwt.

mAx

Uwe
12th February 2007, 20:53
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

mistertoony
13th February 2007, 17:21
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?

aamer4yu
14th February 2007, 04:09
did u use moveTo() before lineTo() ??

mistertoony
14th February 2007, 16:02
did u use moveTo() before lineTo() ??

yes i did. does the QGraphicsScene rely on the cartesian coordinate system? because something is really messed up.

aamer4yu
15th February 2007, 04:17
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 ??