Results 1 to 13 of 13

Thread: Custom symbol for QwtPlotMarker

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Custom symbol for QwtPlotMarker

    ... and what is wrong with calling a virtual function? Nothing, and it has nothing to do with the error message you are getting either I guess.

    How about you actually try to participate in solving your problem in future. Just saying "It doesn't work", or asking over and over and over for someone to give you a canned solution you can copy without thought, is often unproductive and unlikely to win you friends. Tells us what errors you are seeing, what you have tried to fix it etc. Ask a smart question.

    Just to see the end of this, a complete example with a custom pixmap as the symbol for both a marker and the data points:
    Qt Code:
    1. #include <QApplication>
    2. #include <QPainter>
    3.  
    4. #include <qwt_plot_curve.h>
    5. #include <qwt_plot.h>
    6. #include <qwt_plot_marker.h>
    7. #include <qwt_symbol.h>
    8.  
    9. class Symbol:public QwtSymbol
    10. {
    11. public:
    12. Symbol(const QPixmap &pixmap);
    13. QSize boundingSize() const;
    14. void drawSymbols( QPainter *, const QPointF *, int numPoints ) const;
    15. private:
    16. QPixmap m_pixmap;
    17. };
    18.  
    19. Symbol::Symbol(const QPixmap &pixmap):
    20. QwtSymbol(QwtSymbol::UserStyle),
    21. m_pixmap(pixmap)
    22. {
    23. }
    24.  
    25. QSize Symbol::boundingSize() const
    26. {
    27. return m_pixmap.size();
    28. }
    29.  
    30.  
    31. void Symbol::drawSymbols(QPainter *painter, const QPointF *points, int numPoints) const
    32. {
    33. painter->save();
    34. for(int i = 0; i < numPoints; ++i)
    35. painter->drawPixmap(points[i], m_pixmap);
    36. painter->restore();
    37. }
    38.  
    39. int main (int argc, char **argv)
    40. {
    41. QApplication a(argc, argv);
    42.  
    43. const int Size = 30;
    44. double xval[Size];
    45. double yval[Size];
    46. for(int i = 0; i < Size; ++i) {
    47. xval[i] = double(i) * 10.0 / double(Size - 1);
    48. yval[i] = qSin(xval[i]) * qCos(2.0 * xval[i]);
    49. }
    50.  
    51. QwtPlot myPlot;
    52. QwtPlotCurve curve("Curve");
    53. curve.setRawSamples(xval, yval, Size);
    54. QPixmap p1("p1.png");
    55. curve.setSymbol(new Symbol(p1));
    56. curve.attach(&myPlot);
    57.  
    58. mrk.setLinePen(QPen(Qt::black, 0, Qt::DashDotLine));
    59. mrk.setValue(0.5, 0.5);
    60. mrk.setLineStyle(QwtPlotMarker::HLine);
    61. QPixmap p2("p2.png");
    62. mrk.setSymbol(new Symbol(p2));
    63. mrk.attach(&myPlot);
    64.  
    65. myPlot.resize(640,480);
    66. myPlot.show();
    67.  
    68. return a.exec();
    69. }
    To copy to clipboard, switch view to plain text mode 
    Built and tested Qwt 6.0.1 on Linux. Make your own p1.png and p2.png markers.
    Last edited by ChrisW67; 30th May 2012 at 09:05.

  2. The following user says thank you to ChrisW67 for this useful post:

    sonulohani (1st June 2012)

  3. #2
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    29
    Thanked 50 Times in 47 Posts

    Question Re: Custom symbol for QwtPlotMarker

    Thank you ChrisW67, you're awesome.


    Added after 1 34 minutes:


    Sir,
    I want to ask one last thing i.e.; whenever i am trying to write class code i.e.; symbol, in header file then it is giving error as first defined here pointing to constructor. Why is this happening????
    Last edited by sonulohani; 1st June 2012 at 08:48.

  4. #3
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    29
    Thanked 50 Times in 47 Posts

    Cool Re: Custom symbol for QwtPlotMarker

    I understood what is the problem. A very very thanks to you. Its working now. And sorry for querying again and again. I sometimes become insane. But atlast by your help, i figured out what was my mistake. May God bless you.

Similar Threads

  1. QwtPlotMarker example
    By banita in forum Qwt
    Replies: 1
    Last Post: 24th May 2012, 13:19
  2. Replies: 1
    Last Post: 22nd June 2010, 19:56
  3. QwtPlotMarker confusion
    By baray98 in forum Qwt
    Replies: 3
    Last Post: 20th July 2008, 09:47
  4. Replies: 5
    Last Post: 18th March 2008, 09:44

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.