Results 1 to 6 of 6

Thread: QwtPlot - Multiple background-color possible?

  1. #1
    Join Date
    Oct 2013
    Location
    Quebec
    Posts
    31
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default QwtPlot - Multiple background-color possible?

    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

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

    Default Re: QwtPlot - Multiple background-color possible?

    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

  3. #3
    Join Date
    Oct 2013
    Location
    Quebec
    Posts
    31
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QwtPlot - Multiple background-color possible?

    Quote Originally Posted by Uwe View Post
    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/j2j6jcyll8...eBckground.png

    Here is the current code:
    Qt Code:
    1. /// Add Done Shape
    2. lstPointsPower.clear();
    3. btnLeft = QPointF(0, 0 );
    4. topLeft = QPointF(0, 700 );
    5. btnRight = QPointF(60, 0 );
    6. topRight = QPointF(60, 700 );
    7. lstPointsPower.append(btnLeft);
    8. lstPointsPower.append(topLeft);
    9. lstPointsPower.append(topRight);
    10. lstPointsPower.append(btnRight);
    11. addShapeFromPoints("SHAPE_DONE", Qt::gray, lstPointsPower, 1, false);
    12.  
    13. /// Add Todo Shape
    14. lstPointsPower.clear();
    15. btnLeft = QPointF(60, 0 );
    16. topLeft = QPointF(60, 700 );
    17. btnRight = QPointF(time, 0 );
    18. topRight = QPointF(time, 700 );
    19. lstPointsPower.append(btnLeft);
    20. lstPointsPower.append(topLeft);
    21. lstPointsPower.append(topRight);
    22. lstPointsPower.append(btnRight);
    23. addShapeFromPoints("SHAPE_TODO", Qt::black, lstPointsPower, 1, false);
    24.  
    25. void WorkoutPlot::addShapeFromPoints(const QString &title, const QColor &color, QList<QPointF> lstPoints, int positionZ, bool antiliasing) {
    26.  
    27. QwtPlotShapeItem *item;
    28.  
    29. if (title == "SHAPE_TODO") {
    30. shapeWorkoutToDo = new QwtPlotShapeItem(title);
    31. item = shapeWorkoutToDo;
    32. }
    33. else if (title == "SHAPE_DONE") {
    34. shapeWorkoutDone = new QwtPlotShapeItem(title);
    35. item = shapeWorkoutDone;
    36. }
    37. else {
    38. item = new QwtPlotShapeItem(title);
    39. }
    40.  
    41. item->setRenderHint(QwtPlotItem::RenderAntialiased, antiliasing);
    42. item->setShape( ShapeFactory::path(lstPoints));
    43.  
    44. QColor fillColor = color;
    45. fillColor.setAlpha(200);
    46. QPen pen(color, 1);
    47. pen.setJoinStyle(Qt::MiterJoin);
    48. item->setPen(pen);
    49. item->setBrush(fillColor);
    50. item->setZ(positionZ);
    51. item->attach(this);
    52.  
    53. if (title == "PARALLELOGRAM_POWER")
    54. {
    55. lstTargetPower.append(item);
    56. }
    57. else if (title == "PARALLELOGRAM_CADENCE")
    58. {
    59. lstTargetCadence.append(item);
    60. }
    61. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QwtPlot - Multiple background-color possible?

    The screenshot looks more like a QwtPlotZoneItem - see the curvetracker example.

    Uwe

  5. #5
    Join Date
    Oct 2013
    Location
    Quebec
    Posts
    31
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QwtPlot - Multiple background-color possible?

    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!

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

    Default Re: QwtPlot - Multiple background-color possible?

    See playground/curvetracker.

    Uwe

  7. The following user says thank you to Uwe for this useful post:

    Maximus2 (6th March 2014)

Similar Threads

  1. QwtDial - multiple Background color
    By Maximus2 in forum Qwt
    Replies: 3
    Last Post: 26th November 2013, 19:13
  2. Replies: 1
    Last Post: 27th April 2013, 10:31
  3. QwtPlot - multiple axis
    By MukundanAR in forum Qwt
    Replies: 1
    Last Post: 7th March 2012, 07:53
  4. QwtPlot - multiple axis
    By MukundanAR in forum Newbie
    Replies: 0
    Last Post: 6th March 2012, 11:50
  5. Replies: 2
    Last Post: 6th May 2010, 14:09

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.