Results 1 to 12 of 12

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

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

  2. #2
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

  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?

    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...

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

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

    You have to overload QwtPlotCurve::drawLines().

    Uwe

  5. #5
    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?

    Quote Originally Posted by Uwe View Post
    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?

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

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

    Quote Originally Posted by Momergil View Post
    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

  7. #7
    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?

    Quote Originally Posted by Uwe View Post
    This is exactly how to "overload" a virtual method !

    Uwe
    Hmmm ok I'll see what I can do than I return with the results.

  8. #8
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  9. #9
    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?

    Quote Originally Posted by jesse_mark View Post
    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

  10. #10
    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?

  11. #11
    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.

  12. #12
    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.