PDA

View Full Version : QwtPlot - Multiple background-color possible?



Maximus2
3rd March 2014, 19:06
Hi,

I would like to have different background-color for different part of the graph (not the same color for the whole canvas)

for example, at 1:20 in this video (http://www.youtube.com/watch?v=NSCTaG57ze4)
I would like to have a different background at the start of the big graph (0:00 to 1:20) and another background for the rest of the graph (1:20 to 47:30)

The goal is the make the user aware of the workout progress by changing the background-color at every second. I have not found anything yet that could achieve that. Maybe I could use multiple "QwtPlotShapeItem" that I put under every other item of the graph, but that would result in mixed color from superposition of multiple QwtPlotShapeItem

If anyone has an idea to achieve multiple background-color on a QwtPlot let me know ;)
Thanks,

Max

Uwe
3rd March 2014, 21:56
Not sure what you mean by "mixed color from superposition" but If all coordinates of your filled area is in plot coordinates something like QwtPlotShapeItem should be the right item ( beside you need something composed of different pens and brushes ). If some coordinates are plot coordinates, but the others are somehow related to the geometry of the canvas you might need to implement a plot item like QwtPlotZoneItem ( have a look at its implementation and start with it ).

Uwe

Maximus2
4th March 2014, 16:10
Not sure what you mean by "mixed color from superposition" but If all coordinates of your filled area is in plot coordinates something like QwtPlotShapeItem should be the right item ( beside you need something composed of different pens and brushes ). If some coordinates are plot coordinates, but the others are somehow related to the geometry of the canvas you might need to implement a plot item like QwtPlotZoneItem ( have a look at its implementation and start with it ).
Uwe

Thanks Uwe, Forget about color superposition, I was wrong, the output is exactly what I want.
Which method do you recommend for redrawing both QwtPlotShapeItem at every second?
I could just create a new QwtPlotShapeItem over the old pointer, and attach it back to the graph.
Or is there a method that can redraw a QwtPlotShapeItem with new coords? My shape is a rectangle.

Here is a screenshot of a canvas with static colors (will make the color move at interval x)
https://www.dropbox.com/s/j2j6jcyll8ldu4v/interfaceBckground.png

Here is the current code:


/// Add Done Shape
lstPointsPower.clear();
btnLeft = QPointF(0, 0 );
topLeft = QPointF(0, 700 );
btnRight = QPointF(60, 0 );
topRight = QPointF(60, 700 );
lstPointsPower.append(btnLeft);
lstPointsPower.append(topLeft);
lstPointsPower.append(topRight);
lstPointsPower.append(btnRight);
addShapeFromPoints("SHAPE_DONE", Qt::gray, lstPointsPower, 1, false);

/// Add Todo Shape
lstPointsPower.clear();
btnLeft = QPointF(60, 0 );
topLeft = QPointF(60, 700 );
btnRight = QPointF(time, 0 );
topRight = QPointF(time, 700 );
lstPointsPower.append(btnLeft);
lstPointsPower.append(topLeft);
lstPointsPower.append(topRight);
lstPointsPower.append(btnRight);
addShapeFromPoints("SHAPE_TODO", Qt::black, lstPointsPower, 1, false);

void WorkoutPlot::addShapeFromPoints(const QString &title, const QColor &color, QList<QPointF> lstPoints, int positionZ, bool antiliasing) {

QwtPlotShapeItem *item;

if (title == "SHAPE_TODO") {
shapeWorkoutToDo = new QwtPlotShapeItem(title);
item = shapeWorkoutToDo;
}
else if (title == "SHAPE_DONE") {
shapeWorkoutDone = new QwtPlotShapeItem(title);
item = shapeWorkoutDone;
}
else {
item = new QwtPlotShapeItem(title);
}

item->setRenderHint(QwtPlotItem::RenderAntialiased, antiliasing);
item->setShape( ShapeFactory::path(lstPoints));

QColor fillColor = color;
fillColor.setAlpha(200);
QPen pen(color, 1);
pen.setJoinStyle(Qt::MiterJoin);
item->setPen(pen);
item->setBrush(fillColor);
item->setZ(positionZ);
item->attach(this);

if (title == "PARALLELOGRAM_POWER")
{
lstTargetPower.append(item);
}
else if (title == "PARALLELOGRAM_CADENCE")
{
lstTargetCadence.append(item);
}
}

Uwe
4th March 2014, 16:15
The screenshot looks more like a QwtPlotZoneItem - see the curvetracker example.

Uwe

Maximus2
4th March 2014, 16:49
Oh nice didn't know about that class.
for some reason I can't find the curvetracker example in my qwt 6.1.0 source
But I see an example in stockchart/plot.cpp, should be fine with that, thanks!

Uwe
4th March 2014, 17:01
See playground/curvetracker.

Uwe