Results 1 to 3 of 3

Thread: drawArc in the rectangle issues

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2017
    Posts
    1

    Question drawArc in the rectangle issues

    drawArc.jpgwanted.JPGwanted.JPG

    my program will get the startpoints(x,y) and calculate width and height when you draw on the scene, the attached photo shows it.
    the problem is i want to draw a perfect arc in the middle of rectangle as the sketch one attached.
    my code as below:
    Qt Code:
    1. void ResizableRectMarker::paintArc1(int x, int y, int width, int height, QPainter* painter)
    2. {
    3. double radius = sqrt(pow(0.5*width,2)+pow(0.5*height,2));
    4. double step = sqrt(pow(radius,2)-pow(0.5*width,2));
    5.  
    6. QPointF topLeft(x,y);
    7. QPointF bottomRight(x+width,y+height);
    8. QRectF rect(topLeft, bottomRight);
    9.  
    10. int startAngle = atan2(0.5*width,step)* 180 / M_PI * 16;
    11. int spanAngle = 2*startAngle;
    12. qDebug() << "start angle:" << startAngle << "|" << "spanAngle:" << spanAngle;
    13. painter->drawArc(rect, startAngle, spanAngle);
    14. }
    To copy to clipboard, switch view to plain text mode 
    the problem is the the arc drawn is not in the center, and also if the rectangle is not a square, the arc is wired.
    any solution for it.

    newbie here..
    Last edited by anda_skoa; 15th February 2017 at 09:04. Reason: missing [code] tags

Similar Threads

  1. QwtPlotMarker rectangle
    By Khaine in forum Qwt
    Replies: 1
    Last Post: 10th April 2016, 18:08
  2. QPainter drawArc question
    By kloopa in forum Newbie
    Replies: 6
    Last Post: 12th January 2016, 07:29
  3. Replies: 2
    Last Post: 25th December 2014, 15:15
  4. Center point and drawArc
    By seniorc in forum Newbie
    Replies: 1
    Last Post: 24th March 2014, 21:19
  5. Converting MFC CDC::Arc(..) to QPainter->drawArc
    By maverick_pol in forum Qt Programming
    Replies: 8
    Last Post: 26th September 2007, 08:57

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.