Results 1 to 3 of 3

Thread: Dynamically change existing curve color

  1. #1
    Join Date
    Apr 2011
    Location
    Bayreuth, Bayern
    Posts
    24
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Dynamically change existing curve color

    Hey guys,
    I try to dynamically change colors of curves in my Qwt plot depending on user interaction, but I can't figure out how I can force QwtPlot to repaint all curves with new colors. This is the code I use for giving my curves their initial color:

    Qt Code:
    1. Curve::Curve(QColor color) {
    2. QBrush brush;
    3. brush.setColor(color);
    4. brush.setStyle(Qt::SolidPattern);
    5. QPen pen(brush,2,Qt::SolidLine);
    6. this->setPen(pen);
    7. QColor bgColor = color;
    8. bgColor.setAlphaF(0.3f);
    9. brush.setColor(bgColor);
    10. this->setBrush(brush);
    11. this->setRenderHint(QwtPlotItem::RenderAntialiased);
    12. }
    To copy to clipboard, switch view to plain text mode 
    where Curve publicly derives from QwtPlotIntervalCurve.

    I similar Curve::setColor(QColor color) function does not have any impact if I call it after I attach the curve to the plot. Detaching and re-attaching of the curve does not have any impact either. Any ideas how I can dynamically change the color of existing curves?

    Thank you in advance!
    Last edited by missoni; 19th June 2012 at 10:26. Reason: spelling corrections

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

    Default Re: Dynamically change existing curve color

    QwtPlot::replot()

    Uwe

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

    missoni (19th June 2012)

  4. #3
    Join Date
    Apr 2011
    Location
    Bayreuth, Bayern
    Posts
    24
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dynamically change existing curve color

    Thanks Uwe!
    I did in fact use m_plot->replot(), but the problem lay in the color map itself. Due to implicit conversion of float to int I have missed the fact that colors were initialized incorrectly.

    Thanks again!

Similar Threads

  1. Replies: 3
    Last Post: 3rd February 2014, 18:04
  2. Curve with more than one color?
    By sylphide in forum Qwt
    Replies: 1
    Last Post: 16th August 2011, 22:01
  3. Replies: 3
    Last Post: 22nd January 2010, 17:46
  4. how to change backgroup color, button color and shape?
    By lzha022 in forum Qt Programming
    Replies: 10
    Last Post: 16th June 2008, 23:25
  5. How to change the existing color of an object
    By thirupathiuppu007 in forum Qt Programming
    Replies: 3
    Last Post: 10th February 2008, 02:25

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.