Results 1 to 12 of 12

Thread: How to change a QwtPlotCurve color and thickness during the curve?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default 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:

    Qt Code:
    1. QVector<QPointF> samples;
    2. samples.reserve( vetor_ativos[stock].periodicity[period].size() );
    3.  
    4. for (int aaa = 0; aaa < vetor_ativos[stock].periodicity[period].size(); aaa++)
    5. {
    6. if (vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.probability == 0.0f)
    7. continue;
    8.  
    9. samples += QPointF(QwtDate::toDouble(vetor_ativos[stock].periodicity[period][aaa].date),
    10. (double)vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.probability);
    11. }
    To copy to clipboard, switch view to plain text mode 

    My ideia would be about doing a for(; that would catch the data type and depending on the results, change the curve style:

    Qt Code:
    1. QPen up_normal(Qt::green,1.0);
    2. QPen up_continuation(Qt::green,2.0);
    3. QPen up_reversal(Qt::green,3.0);
    4.  
    5. QPen down_normal(Qt::red,1.0);
    6. QPen down_continuation(Qt::red,2.0);
    7. QPen down_reversal(Qt::red,3.0);
    8.  
    9. QPainter painter;
    10.  
    11. for (int aaa = 0; aaa < samples.size(); aaa++)
    12. {
    13. if (vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.foward_direction == DIRECTION_POSITIVE)
    14. {
    15. if (vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.style == CAN_STYLE_CONTINUATION)
    16. {
    17. painter.setPen(up_continuation);
    18.  
    19. }
    20. else if (vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.style == CAN_STYLE_REVERSION)
    21. {
    22.  
    23. }
    24. else
    25. {
    26.  
    27. }
    28. }
    29. else if (vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.foward_direction == DIRECTION_NEGATIVE)
    30. {
    31. if (vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.style == CAN_STYLE_CONTINUATION)
    32. {
    33.  
    34. }
    35. else if (vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.style == CAN_STYLE_REVERSION)
    36. {
    37.  
    38. }
    39. else
    40. {
    41.  
    42. }
    43. }
    44. else
    45. {
    46. if (vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.style == CAN_STYLE_CONTINUATION)
    47. {
    48.  
    49. }
    50. else if (vetor_ativos[stock].periodicity[period][aaa].candle_probability_status.style == CAN_STYLE_REVERSION)
    51. {
    52.  
    53. }
    54. else
    55. {
    56.  
    57. }
    58. }
    59. }
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default 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:

    Qt Code:
    1. void QwtPlotCurveSpecial::setPenVector(QVector<QPen> &vec)
    2. {
    3. v_pen = vec;
    4. }
    5.  
    6. void QwtPlotCurveSpecial::drawLines(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
    7. {
    8. if (from < v_pen.size())
    9. p->setPen(v_pen[from]);
    10.  
    11. QwtPlotCurve::drawLines(p,xMap,yMap,canvasRect,from,to);
    12. }
    To copy to clipboard, switch view to plain text mode 

    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.

  3. #3
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default 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:

    Qt Code:
    1. void QwtPlotCurveSpecial::setPenVector(QVector<QPen> &vec)
    2. {
    3. v_pen = vec;
    4. }
    5.  
    6. void QwtPlotCurveSpecial::drawLines(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
    7. {
    8. for (int counter = 1; counter < v_pen.size(); counter++)
    9. {
    10. if (counter < v_pen.size())
    11. p->setPen(v_pen[counter]);
    12.  
    13. QwtPlotCurve::drawLines(p,xMap,yMap,canvasRect,counter-1,counter);
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    Have a good use!

    Momergil

Similar Threads

  1. Replies: 3
    Last Post: 29th September 2013, 18:51
  2. Dynamically change existing curve color
    By missoni in forum Qwt
    Replies: 2
    Last Post: 19th June 2012, 11:32
  3. Replies: 4
    Last Post: 29th April 2010, 06:11
  4. Replies: 3
    Last Post: 22nd January 2010, 16:46
  5. How can I change the QScrollArea silders thickness?
    By Cédric Syllebranque in forum Qt Programming
    Replies: 2
    Last Post: 31st August 2009, 14:45

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.