Results 1 to 6 of 6

Thread: How to fill curve-sector area in QwtPolar?

  1. #1
    Join Date
    Mar 2016
    Posts
    14
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default How to fill curve-sector area in QwtPolar?

    Hello everyone!
    I know that in QwtPlotCurve exist method setBrush() but how it make in QwtPolarCurve?

  2. #2
    Join Date
    Jul 2015
    Posts
    87
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to fill curve-sector area in QwtPolar?

    A QPen has a QBrush
    QPen::QPen(const QBrush & brush, qreal width, Qt::PenStyle style = Qt::SolidLine, Qt::PenCapStyle cap = Qt::SquareCap, Qt::PenJoinStyle join = Qt::BevelJoin)
    and
    in docu of QwtPolarCurve you will find QwtPolarCurve::setPen (http://qwtpolar.sourceforge.net/)

  3. #3
    Join Date
    Mar 2016
    Posts
    14
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to fill curve-sector area in QwtPolar?

    But it does not filled the sector created by the curve.

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

    Default Re: How to fill curve-sector area in QwtPolar?

    Quote Originally Posted by BulSV View Post
    I know that in QwtPlotCurve exist method setBrush() but how it make in QwtPolarCurve?
    There is no feature like this provided out of the box.

    To implement such a thing you would have to overload QwtPolarCurve::drawLines. You can start with copying the code you find in qwt_polar_curve.cpp to your derived class and remove the code dealing with curve fitting.
    Then have a look at the last 2 lines ( the second line is nonsense and can be removed - there is no reason for drawing twice ):

    Qt Code:
    1. QwtPainter::drawPolyline( painter, polyline );
    2. painter->drawPolyline( polyline );
    To copy to clipboard, switch view to plain text mode 

    Instead of calling drawPolyline you would have to add some lines to polyline ( = the curve points translated in widget coordinates ), so that you have the area you want to fill. Then assign a brush and call QwtPainter::drawPolygon() instead.

    HTH,
    Uwe

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

    BulSV (11th July 2016)

  6. #5
    Join Date
    Mar 2016
    Posts
    14
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to fill curve-sector area in QwtPolar?

    Sorry for the long delay in response - almost a month did not work on this project.
    Quote Originally Posted by Uwe View Post
    To implement such a thing you would have to overload QwtPolarCurve::drawLines. You can start with copying the code you find in qwt_polar_curve.cpp to your derived class and remove the code dealing with curve fitting.
    Then have a look at the last 2 lines ( the second line is nonsense and can be removed - there is no reason for drawing twice ):

    Qt Code:
    1. QwtPainter::drawPolyline( painter, polyline );
    2. painter->drawPolyline( polyline );
    To copy to clipboard, switch view to plain text mode 

    Instead of calling drawPolyline you would have to add some lines to polyline ( = the curve points translated in widget coordinates ), so that you have the area you want to fill. Then assign a brush and call QwtPainter::drawPolygon() instead.
    It didn't work - it is impossible not only to fill, but even change the color of the pen. Can I do something wrong? Here is my code:

    QwtPolarCurveJamming.h
    Qt Code:
    1. #include <qwt_polar_curve.h>
    2.  
    3. class QwtPolarCurveJamming : public QwtPolarCurve
    4. {
    5. protected:
    6. void drawLines( QPainter *,
    7. const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
    8. const QPointF &pole, int from, int to ) const;
    9. };
    To copy to clipboard, switch view to plain text mode 

    QwtPolarCurveJamming.cpp
    Qt Code:
    1. #include "qwt_polar_curve.h"
    2. #include "qwt_polar.h"
    3. #include <qwt_painter.h>
    4. #include <qwt_scale_map.h>
    5. #include <qwt_math.h>
    6. #include <qwt_symbol.h>
    7. #include <qwt_legend.h>
    8. #include <qwt_curve_fitter.h>
    9. #include <qwt_clipper.h>
    10. #include <qpainter.h>
    11. #include "QwtPolarCurveJamming.h"
    12.  
    13. static inline bool qwtInsidePole( const QwtScaleMap &map, double radius )
    14. {
    15. return map.isInverting() ? ( radius > map.s1() ) : ( radius < map.s1() );
    16. }
    17.  
    18. void QwtPolarCurveJamming::drawLines( QPainter *painter,
    19. const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
    20. const QPointF &pole, int from, int to ) const
    21. {
    22. int size = to - from + 1;
    23. if ( size <= 0 )
    24. return;
    25.  
    26. QPolygonF polyline;
    27. polyline.resize( size );
    28. QPointF *polylineData = polyline.data();
    29.  
    30. for ( int i = from; i <= to; i++ )
    31. {
    32. QwtPointPolar point = sample( i );
    33. if ( !qwtInsidePole( radialMap, point.radius() ) )
    34. {
    35. double r = radialMap.transform( point.radius() );
    36. const double a = azimuthMap.transform( point.azimuth() );
    37. polylineData[i - from] = qwtPolar2Pos( pole, r, a );
    38. }
    39. else
    40. {
    41. polylineData[i - from] = pole;
    42. }
    43. }
    44.  
    45. /*QRectF clipRect;
    46.   if ( painter->hasClipping() )
    47.   clipRect = painter->clipRegion().boundingRect();
    48.   else
    49.   {
    50.   clipRect = painter->window();
    51.   if ( !clipRect.isEmpty() )
    52.   clipRect = painter->transform().inverted().mapRect( clipRect );
    53.   }
    54.  
    55.   if ( !clipRect.isEmpty() )
    56.   {
    57.   double off = qCeil( qMax( qreal( 1.0 ), painter->pen().widthF() ) );
    58.   clipRect = clipRect.toRect().adjusted( -off, -off, off, off );
    59.   polyline = QwtClipper::clipPolygonF( clipRect, polyline );
    60.   }*/
    61.  
    62. painter->setBrush(QBrush(Qt::red));
    63. painter->setPen(Qt::red);
    64. // painter->drawPolygon(polyline);
    65. // QwtPainter::fillRect(painter, polyline.boundingRect(), QBrush(Qt::red));
    66. QwtPainter::drawPolygon(painter, polyline);
    67. // QwtPainter::drawPolyline( painter, polyline );
    68. // painter->drawPolyline( polyline );
    69. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by BulSV; 1st May 2016 at 00:02.

  7. #6
    Join Date
    Mar 2016
    Posts
    14
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Smile Re: How to fill curve-sector area in QwtPolar?

    Finally it works!
    I changed method drawLines() in the file "qwt_polar_curve.h" from "void drawLines()" to "virtual void drawLines()" and recompiled qwtpolar library.

Similar Threads

  1. Replies: 5
    Last Post: 17th December 2014, 12:07
  2. Replies: 3
    Last Post: 16th December 2014, 05:43
  3. Replies: 10
    Last Post: 7th March 2012, 18:22
  4. Replies: 3
    Last Post: 7th September 2011, 12:26
  5. Fill area of QPainterPath
    By vides2012 in forum Qt Programming
    Replies: 6
    Last Post: 17th June 2011, 13:00

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.