Results 1 to 4 of 4

Thread: Who can draw this Area with QPainter?

  1. #1
    Join Date
    Jul 2013
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Question Who can draw this Area with QPainter?

    Untitled.jpg

    how can draw this are with QPainter?

    I used two pie with composite mode but i wasn't success ((

    please help me

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Who can draw this Area with QPainter?

    Try this
    Qt Code:
    1. class Painter : public QWidget
    2. {
    3. public:
    4. explicit Painter(QWidget * parent = 0) : QWidget(parent) { }
    5.  
    6. QSize sizeHint(void) const { return QSize(500, 500); }
    7.  
    8. protected:
    9. void paintEvent(QPaintEvent * event)
    10. {
    11. const int arkWidth = 40;
    12. const QRect & rect = event->rect();
    13. const int side = qMin(rect.height(), rect.width());
    14.  
    15. if(side < (arkWidth * 2))
    16. return;
    17.  
    18. QPainter painter(this);
    19.  
    20. QPen pen = painter.pen();
    21. pen.setColor(Qt::darkBlue);
    22. pen.setWidth(arkWidth);
    23. painter.setPen(pen);
    24.  
    25. const int margin = pen.width();
    26. QRect r(0, 0, side, side);
    27. r.adjust(0, 0, -margin, -margin);
    28. r.moveCenter(rect.center());
    29.  
    30. const int start = 20;
    31. const int end = 180 - start * 2;
    32.  
    33. painter.drawArc(r, start * 16, end * 16);
    34. }
    35. };
    To copy to clipboard, switch view to plain text mode 
    Last edited by Santosh Reddy; 13th July 2013 at 13:01.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jul 2013
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Who can draw this Area with QPainter?

    tnx Santosh , but i want to draw width of area dynamically with 500 pixel to 800 pixel Arc width and with these the area is not suitable (

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Who can draw this Area with QPainter?

    Use clipping to obtain the effect you want. Alternatively you can probably obtain a similar effect using QPainterPath.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. how to draw area
    By stevocz in forum Qt Programming
    Replies: 2
    Last Post: 29th May 2013, 12:42
  2. Replies: 3
    Last Post: 14th February 2012, 12:37
  3. Replies: 1
    Last Post: 8th October 2011, 19:15
  4. Using QPainter to 'erase' an area of widget?
    By altec42lansing in forum Qt Programming
    Replies: 13
    Last Post: 17th June 2011, 16:19
  5. Replies: 19
    Last Post: 26th November 2008, 19:54

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.