Results 1 to 4 of 4

Thread: How does one draw a 'cut down' ellipse using QPainter

  1. #1
    Join Date
    Aug 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default How does one draw a 'cut down' ellipse using QPainter

    I need to draw a circle within a QPixmap, where the radius of the circle is slightly too big to fit inside the pixmap. The following code draws the circle nicely enough (with a cross and a square as well for good measure):

    Qt Code:
    1. painter.setViewport(m_originX, m_originY, m_sideX, m_sideY);
    2. painter.setWindow(0, 0, m_pixmap.width(), m_pixmap.height());
    3.  
    4. painter.drawPixmap(0, 0, m_pixmap);
    5.  
    6. painter.drawLine(centre.x() - 20, centre.y(), centre.x() + 20, centre.y());
    7. painter.drawLine(centre.x(), centre.y() - 20, centre.x(), centre.y() + 20);
    8. painter.drawRect(centre.x(), centre.y(), squareSize, squareSize);
    9. painter.drawEllipse(centre.x(), centre.y(), circleSize, circleSize););
    To copy to clipboard, switch view to plain text mode 

    Capture.JPG

    ...except that the parts of the circle outside the QPixmap are also drawn. What I'd really like is to draw only the parts of the circle that lie within the QPixmap, so no lines are visible outside of the image.

    Can this be done?

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How does one draw a 'cut down' ellipse using QPainter

    qpainter.drawArc
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    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: How does one draw a 'cut down' ellipse using QPainter

    ... or clip the painter.
    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.


  4. The following user says thank you to wysota for this useful post:

    Eos Pengwern (24th July 2012)

  5. #4
    Join Date
    Aug 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How does one draw a 'cut down' ellipse using QPainter

    Perfect, that is the solution. Thank you.

Similar Threads

  1. Draw line on image using QPainter
    By Qt Coder in forum Qt Programming
    Replies: 29
    Last Post: 11th August 2015, 12:09
  2. how to draw points with qpainter?
    By athulms in forum Newbie
    Replies: 4
    Last Post: 23rd August 2011, 08:10
  3. How to draw a semi circle or arc of ellipse
    By parnedo in forum Qt Programming
    Replies: 2
    Last Post: 2nd July 2009, 01:39
  4. How to draw soft shadow with QPainter?
    By troorl_ua in forum Qt Programming
    Replies: 9
    Last Post: 13th October 2008, 13:01
  5. how to display an Ellipse on a Qpainter.
    By mahe2310 in forum Qt Programming
    Replies: 6
    Last Post: 1st March 2006, 14:19

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.