Results 1 to 6 of 6

Thread: rotating a custom made symbol for QwtPlotCurve

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: rotating a custom made symbol for QwtPlotCurve

    hi
    i have subclassed the QwtPlotCurve like this .

    Qt Code:
    1. #include <QtGui>
    2. #include "qwt_plot.h"
    3. #include "qwt_plot_curve.h"
    4. #include "qwt_valuelist.h"
    5. #include "qwt_scale_div.h"
    6. #include "qwt_symbol.h"
    7. #include "qwt_painter.h"
    8. class feather : public QwtSymbol
    9. {
    10. public:
    11.  
    12. void draw(QPainter *painter, const QRect &r) const
    13. {
    14. //painter->translate(r.topLeft());
    15.  
    16. //shape |_|__
    17. QwtPainter::drawLine(painter, r.bottomLeft(), r.topLeft());
    18. QwtPainter::drawLine(painter, r.bottomLeft(), r.bottomRight());
    19. QwtPainter::drawLine(painter, r.right()-r.width()/2, r.bottom(),
    20. r.right()-r.width()/2, r.top());
    21. }
    22. };
    23.  
    24. class curve_data : public QwtPlotCurve
    25. {
    26. public:
    27. void drawSymbols(QPainter *painter, const QwtSymbol &symbol,
    28. const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
    29. {
    30. QRect rect;
    31. rect.setSize(QwtPainter::metricsMap().screenToLayout(symbol.size()));
    32.  
    33. for (int i = from; i <= to; i++)
    34. {
    35. const int xi = xMap.transform(x(i));
    36. const int yi = yMap.transform(y(i));
    37. rect.moveCenter(QPoint(xi, yi));
    38. painter->setPen(QPen(Qt::blue));
    39.  
    40. feather f;
    41. f.draw(painter, rect);
    42. }
    43. }
    44. };
    45.  
    46. int main(int argc, char *argv[])
    47. {
    48. QApplication a(argc, argv);
    49. QwtPlot *qwt =new QwtPlot;
    50. qwt->setCanvasBackground(QColor(Qt::white));
    51.  
    52. //set scale for x-axis
    53. qwt->setAxisScale(QwtPlot::xBottom, 13, 0);
    54. qwt->setAxisMaxMajor(QwtPlot::xBottom, 24);
    55. qwt->setAxisMaxMinor(QwtPlot::xBottom, 0);
    56.  
    57. //set scale for y-axis
    58. qwt->setAxisScale(QwtPlot::yLeft, 0, 31);
    59.  
    60. //create data for curve
    61. int MAX=12*30;
    62. double x[MAX], y[MAX];
    63. int k=1;
    64. int l=1;
    65.  
    66. for (int i=0; i<MAX; i++)
    67. {
    68. x[i]=k;
    69. y[i]=l;
    70. k++;
    71. if (k>12)
    72. {
    73. k=1;
    74. l++;
    75. }
    76. }
    77.  
    78. //create symbol for curve
    79. feather sym;
    80. sym.setStyle(QwtSymbol::Cross);
    81. sym.setSize(30, 10);
    82.  
    83. //create curve , set symbol and data to curve
    84. curve_data *cur=new curve_data;
    85. cur->setStyle(QwtPlotCurve::NoCurve);
    86. cur->setSymbol(sym);
    87. cur->setData(x, y, MAX);
    88. cur->attach(qwt);
    89.  
    90. qwt->resize(800, 600);
    91. qwt->show();
    92.  
    93. return a.exec();
    94. }
    To copy to clipboard, switch view to plain text mode 

    i get the symbols , but i need to rotate individual symbols at different angles.
    Last edited by babu198649; 17th March 2008 at 12:33.

Similar Threads

  1. Replies: 16
    Last Post: 23rd May 2008, 10:12
  2. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 22:04

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.