PDA

View Full Version : draw curve



szisziszilvi
20th January 2011, 15:14
Hello,

I'm using QPainterPath to draw a curve on a QGraphicsView (this should be a graph later), and now I find it possible that I'm on a wrong way.

Here is the result (concentrate on the blue thing):
http://szisziszilvi.lima-city.de/temp/qtQuestions/painterpath_1.jpg
This is surely not what I meant.
The black sinus dots a bit below works fine, but these are just dots, not a smooth line.
Furthermore when I want to use the shortcut for the button, by pressing the "Alt" the image redraws the path, and I don't really understand what happens. I mean I gues by pressing Alt it redraws each item sent to the GraphichsView, but what does it draw now? The second one is this:
http://szisziszilvi.lima-city.de/temp/qtQuestions/painterpath_2.jpg

Well, I'm "simply" searching for the solution, any ideas are welcome.

this is the reimplementation of the paint function: (anyway, this was meant to have a hole in the middle, which now I find possible that it not possible with QPainterPath)
related declarations:

int maxDataNum;
QPainterPath qpp;
QPointF * qpf; ... later qpf = new QPointF[maxDataNum]; when it is set.



void pathGraphItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
int i;
for( i = 1; i < maxDataNum; i++)
{
if(!qpf[i-1].isNull() && !qpf[i].isNull())
{
qpp.quadTo(qpf[i-1],qpf[i]);
}

}

painter->setBrush(Qt::blue);
painter->drawPath(qpp);
}

totem
21st January 2011, 08:14
The black sinus dots a bit below works fine, but these are just dots, not a smooth line.

And what do you expect to obtain with the pathGraphItem::paint() code you provided ? A blue line ? blue dots ?
Can you show the paint method used to paint the "black sinus dots" ?

If you want a blue line I'd say you can get rid of this :

painter->setBrush(Qt::blue);
and replace it by

QPen _pen(Qt::blue) ;
_pen.setWidthF(0) ;
_pen.setStyle(Qt::DotLine) ;
painter->setPen(_pen);
painter->setBrush(Qt::NoBrush);


Also, concerning the "hole in the middle", this is maybe what you are looking for :

QPainterPath path ;
path.moveTo( firstPos ) ; // you may have forgotten this step by the way
path.quadTo( posBeforeHole) ;

path.moveTo( posAfterHole ) ;
path.quadTo( lastPos ) ;

szisziszilvi
21st January 2011, 10:05
And what do you expect to obtain with the pathGraphItem:: paint() code you provided ?
a simple, smooth line. I guess I chose a wrong object to derive from.

Yes, I've forgotten that step you mentioned as I didn't find it interesting, this might be a misunderstanding point. I tryed this, AND WORKED!!! :)
Anyway, it might be helpful for the others that quadTo needs two parameter, so the function now looks like this:


void pathGraphItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
int i;
for( i = 1; i < maxDataNum; i++)
{
if(!qpf[i-1].isNull() && !qpf[i].isNull())
{
qpp.moveTo(qpf[i-1]);
qpp.quadTo(qpf[i-1],qpf[i]);
}

}
painter->setBrush(Qt::blue);
painter->drawPath(qpp);
}

d_stranz
23rd January 2011, 01:20
You might find that it is a whole lot easier to simply use Qwt instead of inventing your own plotting widget.

http://qwt.sourceforge.net

szisziszilvi
24th January 2011, 12:31
yeah, I know, but I just could not figure out how to build that. But I would happily take someone's help to do that. I remember some strange moments which I couldn't explain, like I tried to make more than one time and although I did nothing to the project files the amount of warning messages started to reduce, but I can't remember what happened really. So maybe a real-time help could be the best. So that's how I started to build my own solution. But still it was worth as I learned a lot from this.

d_stranz
24th January 2011, 16:18
yeah, I know, but I just could not figure out how to build that. But I would happily take someone's help to do that. I remember some strange moments which I couldn't explain, like I tried to make more than one time and although I did nothing to the project files the amount of warning messages started to reduce, but I can't remember what happened really. So maybe a real-time help could be the best. So that's how I started to build my own solution. But still it was worth as I learned a lot from this.

OK, but what is more important to you? Getting your app to work and do what you want it to, or spending a lot of time writing a plotting widget that already exists? You -are- learning something, that's true, but it sounds like it is frustrating.

Building Qwt is easy. I don't know what platform you are on, but just use the .pro file with qmake. Any of the Qwt example programs will show you how to incorporate it into your own app.

szisziszilvi
25th January 2011, 08:38
OK, but what is more important to you? Getting your app to work and do what you want it to, or spending a lot of time writing a plotting widget that already exists? You -are- learning something, that's true, but it sounds like it is frustrating.
well, honestly actually both. :) It's rather like a game for me, not really anything annoying.


Building Qwt is easy. I don't know what platform you are on, but just use the .pro file with qmake. Any of the Qwt example programs will show you how to incorporate it into your own app.
XP. But I thing I will open a new thread for this topic as it is not the question of using any "qpainting" device.