Results 1 to 7 of 7

Thread: Multiple curves with both dots and lines

  1. #1
    Join Date
    Nov 2010
    Posts
    19
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Multiple curves with both dots and lines

    Hi, I need to do something like this


    Basically I need to do two things:

    1) Plot one or more curves

    2) Draw a symbol at each sample and the line connecting two samples

    I think the first can be done by attaching two QwtPlotCurve objects to the same QwtPlot. For the second I've tried this
    Qt Code:
    1. QwtPlotCurve::CurveStyle style = (QwtPlotCurve::CurveStyle)(QwtPlotCurve::Lines|QwtPlotCurve::Dots);
    To copy to clipboard, switch view to plain text mode 
    but it does not work. Any ideas?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Multiple curves with both dots and lines

    This is not correct:

    Qt Code:
    1. QwtPlotCurve::CurveStyle style = (QwtPlotCurve::CurveStyle)(QwtPlotCurve::Lines|QwtPlotCurve::Dots);
    To copy to clipboard, switch view to plain text mode 

    CurveStyle is not like a Qt::Flags argument - you can't logically OR curve styles. You get to pick just one.

    To implement what you want, simply use Lines style, and set a symbol:

    Qt Code:
    1. QwtSymbol symbol( QwtSymbol::Rect );
    2. myCurve->setSymbol( symbol );
    To copy to clipboard, switch view to plain text mode 

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

    Patrik (10th January 2011)

  4. #3
    Join Date
    Nov 2010
    Posts
    19
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multiple curves with both dots and lines

    Ok, after setting also a symbol size it works. Thank you
    Last edited by Patrik; 10th January 2011 at 17:40.

  5. #4
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Multiple curves with both dots and lines

    Quote Originally Posted by Patrik View Post
    I see no symbols
    of course not. you create "symbol" as a local variable and pass a pointer on it.

    try
    Qt Code:
    1. curve->setSymbol(QwtSymbol(QwtSymbol::Ellipse));
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Multiple curves with both dots and lines

    Quote Originally Posted by FelixB View Post
    of course not. you create "symbol" as a local variable and pass a pointer on it.

    try
    Qt Code:
    1. curve->setSymbol(QwtSymbol(QwtSymbol::Ellipse));
    To copy to clipboard, switch view to plain text mode 
    There is no difference between what you suggest and my code. Your code does not pass a pointer to a QwtSymbol, it passes a reference. If you actually tried to pass a pointer, the code would fail to compile, since setSymbol() takes a "const QwtSymbol &" argument. Furthermore, your code does not allow setting a symbol size, as Patrik noted, since you have no way to access the reference once the setSymbol() call returns.

    So for completeness, my code should be updated to read something like this:

    Qt Code:
    1. QwtSymbol symbol( QwtSymbol::Rect );
    2. symbol.setSize( QSize( 5, 5) );
    3. myCurve->setSymbol( symbol );
    To copy to clipboard, switch view to plain text mode 

  7. #6
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Multiple curves with both dots and lines

    Quote Originally Posted by d_stranz View Post
    Your code does not pass a pointer to a QwtSymbol, it passes a reference.
    yes. That is the correct way to do it. I never said that I wanted to pass a pointer. I said to patrik that he passed a pointer in his code (which is edited now).

    Quote Originally Posted by d_stranz View Post
    Furthermore, your code does not allow setting a symbol size, as Patrik noted, since you have no way to access the reference once the setSymbol() call returns.
    Qt Code:
    1. curve->setSymbol(QwtSymbol(QwtSymbol::Rect));
    2. //...
    3. QwtSymbol symbol = myCurve->symbol();
    4. symbol.setSize(Qsize(5,5));
    5. curve->setSymbol(symbol);
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by d_stranz View Post
    So for completeness, my code should be updated to read something like this:

    Qt Code:
    1. QwtSymbol symbol( QwtSymbol::Rect );
    2. symbol.setSize( QSize( 5, 5) );
    3. myCurve->setSymbol( symbol );
    To copy to clipboard, switch view to plain text mode 
    I'd suggest
    Qt Code:
    1. myCurve->setSymbol(QwtSymbol ( QwtSymbol::Rect , QBrush(myCurve->pen().color()), QPen(myCurve->pen().color()), QSize(5,5)));
    To copy to clipboard, switch view to plain text mode 

  8. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Multiple curves with both dots and lines

    Yes, that would work just as well.

    I guess I find that it makes code more readable (and easier to debug) if I use a local object and change its properties stepwise than to do it in a single method call as you have done. It makes for more code, but if someone else has to come later and understand what I have done, simple code is usually easier to understand. I also think it is easier to spot a mistake in short lines of code than in long ones.

    In order to debug your single line of code, you'll have to step in and out of 4 constructors and at least 4 method calls to resolve the setSymbol() arguments before you actually get into the setSymbol code itself. (Or you could set a breakpoint inside setSymbol(), but that might be too late or get called too often from other parts of the code).

    But we each have our own styles.

    I said to patrik that he passed a pointer in his code (which is edited now).
    Patrik apparently edited his post to delete some things between the time you posted your reply and the time I read it. I don't know if there is a way to display the edit history.

Similar Threads

  1. Replies: 8
    Last Post: 29th July 2011, 15:54
  2. Replies: 2
    Last Post: 6th July 2010, 15:21
  3. Select multiple curves
    By aimsc in forum Qwt
    Replies: 2
    Last Post: 30th October 2009, 11:45
  4. Replies: 2
    Last Post: 1st August 2009, 12:44
  5. Multiple curves on top of each other
    By jmsbc in forum Qwt
    Replies: 2
    Last Post: 15th July 2009, 20:46

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.