Results 1 to 8 of 8

Thread: How to draw a special circle pie

  1. #1
    Join Date
    Jul 2009
    Posts
    17
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to draw a special circle pie

    Hi everybody.

    I've a little problem, i need to draw a circle pie but in a special manner

    I want to draw the border of the circle an fill it but not the lines what goes to the centre.

    Like in the attached image

    I have tried with ellipse but i cannot change the color of the lines to the centre.
    Attached Images Attached Images

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to draw a special circle pie

    first draw the pie without border and then draw the arc on top of it of desired length

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

    parnedo (3rd July 2009)

  4. #3
    Join Date
    Jul 2009
    Posts
    17
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to draw a special circle pie

    If i have this. How can i set the pen and brush of arc and fill separately?

    Qt Code:
    1. #include <QApplication>
    2. #include <QGraphicsPathItem>
    3. #include <QGraphicsScene>
    4. #include <QGraphicsView>
    5. #include <QDebug>
    6.  
    7. int main( int argc, char **argv )
    8. {
    9. QApplication app(argc, argv);
    10.  
    11. //arc
    12. QPainterPath arc(QPoint(50,50));
    13. arc.arcMoveTo(0,0,100,100,45);
    14. arc.arcTo(0, 0,100,100,45, 100);
    15.  
    16. // fill
    17. QPainterPath fill(QPoint(50,50));
    18. fill.arcTo(0,0,100,100,45, 100);
    19. fill.closeSubpath();
    20.  
    21. // total path
    22. QPainterPath total = fill.united(arc);
    23.  
    24. //item with two paths
    25. QGraphicsPathItem item(total);
    26. item.setPen(QPen(QColor(0, 0, 0), 5));
    27. item.setBrush(QBrush(QColor(100, 100, 100)));
    28.  
    29. // scene
    30. scene.setSceneRect(-100, -100, 250.0, 250.0 );
    31. scene.addItem(&item);
    32.  
    33. QGraphicsView view( &scene );
    34. view.show();
    35. return app.exec();
    36. }
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to draw a special circle pie

    If you use QGraphicsScene simple use QGraphicsEllipseItem and set a proper pen and brush for your painter.

    Qt Code:
    1. item->setStartAngle(...);
    2. item->setSpanAngle(...);
    3. item->setPen(Qt::Black);
    4. item->setBrush(QColor(255, 150, 50));
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Jul 2009
    Posts
    17
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to draw a special circle pie

    Quote Originally Posted by Lykurg View Post
    If you use QGraphicsScene simple use QGraphicsEllipseItem and set a proper pen and brush for your painter.

    Qt Code:
    1. item->setStartAngle(...);
    2. item->setSpanAngle(...);
    3. item->setPen(Qt::Black);
    4. item->setBrush(QColor(255, 150, 50));
    To copy to clipboard, switch view to plain text mode 
    But that gives to me the arc of ellipse with the arc and the two radius black , and i only want the arc to be painted (as the image at the first post)

    I need to know if i can change the pen and brush of a QPainterPath

  7. #6
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    69
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to draw a special circle pie

    Hi,
    Quote Originally Posted by parnedo View Post
    I need to know if i can change the pen and brush of a QPainterPath
    Try it. If it don't work you can create two QPainterPaths, one for the pie and the other one for the arc. Paint first the pie and then the arc as MrDeath suggested.
    Òscar Llarch i Galán

  8. #7
    Join Date
    Jul 2009
    Posts
    17
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to draw a special circle pie

    Quote Originally Posted by ^NyAw^ View Post
    Hi,


    Try it. If it don't work you can create two QPainterPaths, one for the pie and the other one for the arc. Paint first the pie and then the arc as MrDeath suggested.
    I can't try because as i said i don't know how to change the pen and brush of a QPainterPath

  9. #8
    Join Date
    Jul 2009
    Posts
    17
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to draw a special circle pie

    I have found a solution.
    I post it for any one who needs it.

    Class derived from QGraphicsItem:

    Qt Code:
    1. void TArcEllipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget){
    2.  
    3. painter->setPen(QPen(myBrush.color(), 0));
    4. painter->setBrush(myBrush);
    5. painter->setBackgroundMode(Qt::OpaqueMode);
    6. painter->drawPie(x, y, w,h, angle, degrees);
    7.  
    8. painter->setPen(myPen);
    9. painter->drawArc(x, y, w,h, angle, degrees);
    10. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How to draw a semi circle or arc of ellipse
    By parnedo in forum Qt Programming
    Replies: 2
    Last Post: 2nd July 2009, 02:39
  2. partly draw in textEdit.
    By gikidy in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2009, 19:43
  3. Use delegate to draw different type of items
    By nifei in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2009, 14:16
  4. help regarding circle
    By jjbabu in forum Qt Programming
    Replies: 2
    Last Post: 20th September 2007, 11:23
  5. What is the fastest way to draw a circle ?
    By Vladimir in forum Qt Programming
    Replies: 18
    Last Post: 6th September 2007, 18:26

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.