How to change a QwtPlotCurve color and thickness during the curve?
Hello!
I need to change the thickness and the color of a unique QwtPlotCurve during its plotting, i.e., depending on the way the new curve point is, the color of the curve from the previous point to this new one may vary as well as its thickness. How do I do this with only one QwtPlotCurve?
Thanks,
Momergil
Re: How to change a QwtPlotCurve color and thickness during the curve?
if you mean different colors and different thickness between each point and another point on the same curve ?? i dont think that is possible man.
why not use different curves ??for each colors and thickness ??
Re: How to change a QwtPlotCurve color and thickness during the curve?
As far as I understand QwtPlotCurve, that would not just be a mess and a tremendous memory consumption but its also unacceptable.
For example: imagine that I have 1000 points and each new point has such configuration that each new draw the curve must alternate the color and thicknes from so blue-red-blue and 1.0-2.0-1.0. That means that if I were going to create a new QwtPlotCurve for each new point, that would make 1000 QwtPlotCurve, a new one with specific color-thickness for each point! That would be a mess in terms of creating 1000 objects, not to mention time and memory consumption.
Another thing that one could imagine is to create only four QwtPlotCurve and make their drawing alternate, so e.g. for between points 1 and 2 I use QwtPlotCurve[0], than between 2 and 4 QwtPlotCurve[0] remains hidden (i.e. don't make any connection) while the others QwtPlotCurve[1-3] do a similar work. The problem is that as far as I know QwtPLotCurve necessarely connect the dots in the sample series; no way of creating such "gaps".
What I need is the possibility to tell the QwtPlotCurve "look, from now one you will draw with thickness X and clor Y till I change this configuration".
I just hope I'll not end up having to change Qwt's source code to have such functionallity :x
P.s.: if you think that my example is unacceptable, I'm working actually with 10000+ points...
Re: How to change a QwtPlotCurve color and thickness during the curve?
You have to overload QwtPlotCurve::drawLines().
Uwe
Re: How to change a QwtPlotCurve color and thickness during the curve?
Quote:
Originally Posted by
Uwe
You have to overload QwtPlotCurve::drawLines().
Uwe
Hmm I see. But how exactly should I do this? I mean, must I overload the function in the original qwt 6.1 files and than recompile and reinstall it?
Besides, wouldn't it be better/simpler to create another class that inherits QwtPlotCurve and than create this new drawLines() on it?
Any other tip?
Re: How to change a QwtPlotCurve color and thickness during the curve?
Quote:
Originally Posted by
Momergil
Besides, wouldn't it be better/simpler to create another class that inherits QwtPlotCurve and than create this new drawLines() on it?
This is exactly how to "overload" a virtual method !
Uwe
Re: How to change a QwtPlotCurve color and thickness during the curve?
Quote:
Originally Posted by
Uwe
This is exactly how to "overload" a virtual method !
Uwe
Hmmm ok :D I'll see what I can do than I return with the results.
Re: How to change a QwtPlotCurve color and thickness during the curve?
did you got any new result, man ??
I am interested to see/know how you did that?? its
Re: How to change a QwtPlotCurve color and thickness during the curve?
Quote:
Originally Posted by
jesse_mark
did you got any new result, man ??
I am interested to see/know how you did that?? its
Oh, actually not. While I need some day to do this, I wasn't in a hurry to do it; it's not a priority in my software :P
But since there is someonelse interested on it, i'll concentrate myself on this as soon as possible :)
Re: How to change a QwtPlotCurve color and thickness during the curve?
So, after some investigation...
I found out that I have no idea whatsoever about how to do this ^^
Problems I found:
the differentiantion in thickness and color is not relative to the y or x value of the curve; rather it's based on uchar values outisde the implementation of the curve (it's a vector that hold the Y points and the uchar values, so I copied the Y data to a new QPointF values and that I put inside the curve:
Code:
QVector<QPointF> samples;
samples.reserve( vetor_ativos[stock].periodicity[period].size() );
for (int aaa = 0; aaa < vetor_ativos[stock].periodicity[period].size(); aaa++)
{
if (vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.probability == 0.0f)
continue;
samples
+= QPointF(QwtDate
::toDouble(vetor_ativos
[stock
].
periodicity[period
][aaa
].
date),
(double)vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.probability);
}
My ideia would be about doing a for(;;) that would catch the data type and depending on the results, change the curve style:
Code:
QPen up_normal
(Qt
::green,
1.0);
QPen up_continuation
(Qt
::green,
2.0);
QPen up_reversal
(Qt
::green,
3.0);
QPen down_normal
(Qt
::red,
1.0);
QPen down_continuation
(Qt
::red,
2.0);
QPen down_reversal
(Qt
::red,
3.0);
for (int aaa = 0; aaa < samples.size(); aaa++)
{
if (vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.foward_direction == DIRECTION_POSITIVE)
{
if (vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.style == CAN_STYLE_CONTINUATION)
{
painter.setPen(up_continuation);
}
else if (vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.style == CAN_STYLE_REVERSION)
{
}
else
{
}
}
else if (vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.foward_direction == DIRECTION_NEGATIVE)
{
if (vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.style == CAN_STYLE_CONTINUATION)
{
}
else if (vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.style == CAN_STYLE_REVERSION)
{
}
else
{
}
}
else
{
if (vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.style == CAN_STYLE_CONTINUATION)
{
}
else if (vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.style == CAN_STYLE_REVERSION)
{
}
else
{
}
}
}
But simply overloading drawLines(...) don't seems to have any good, once I have no way of exctracting the parameters values to use the function. Does somebody have any idea? Any other way of how to do this?
Re: How to change a QwtPlotCurve color and thickness during the curve?
Ok, I guess I found a solution while I was taking a bath :P
This are the different parts of my new class that inherits QwtPlotCurve:
Code:
void QwtPlotCurveSpecial::setPenVector(QVector<QPen> &vec)
{
v_pen = vec;
}
{
if (from < v_pen.size())
p->setPen(v_pen[from]);
}
As you may see, I calibrate a QVector<QPen> vector to hold the QPen appropriate for each draw of the curve. I'm not sure actually if it works because the base algorithm to use this implementation is not ready, but you may use it for personal tests.
Re: How to change a QwtPlotCurve color and thickness during the curve?
Ok, the above code actually don't work... Here is the final version:
Code:
void QwtPlotCurveSpecial::setPenVector(QVector<QPen> &vec)
{
v_pen = vec;
}
{
for (int counter = 1; counter < v_pen.size(); counter++)
{
if (counter < v_pen.size())
p->setPen(v_pen[counter]);
QwtPlotCurve::drawLines(p,xMap,yMap,canvasRect,counter
-1,counter
);
}
}
Have a good use! :)
Momergil