Results 1 to 11 of 11

Thread: Why isn't QPainterPath::intersects giving me the expected result?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Why isn't QPainterPath::intersects giving me the expected result?

    I made the following test code for the QPainterPath::intersects test function. I wanted a way to detect if a point is in the vicinity (let's say 2 pixels) of a line stored in a QPainterPath.

    Qt Code:
    1. path.moveTo(0, 0);
    2. path.lineTo(0, -20);
    3. path.lineTo(40, -20);
    4. path.lineTo(40, -95);
    5. int testX = 4;
    6. int testY = -17;
    7. QRectF rect(testX - 2, testY - 2, 4, 4);
    8. bool intersects = path.intersects(rect);
    9. qDebug() << "Intersects?" << ((intersects) ? "true" : "false");
    10. qDebug() << "Rect: x =" << rect.x() << "| y =" << rect.y() << "| w =" << rect.width() << "| h =" << rect.height();
    To copy to clipboard, switch view to plain text mode 

    This produces the following output:
    Intersects? true
    Rect: x = 2 | y = -19 | w = 4 | h = 4
    I'd expect the intersects function to return false in this case because no point in the rectangle overlaps with the drawn line. Am I using the function incorrectly?
    Last edited by blooglet; 12th May 2011 at 13:27. Reason: spelling corrections

Similar Threads

  1. QPainterPath::quadTo(...) calls QPainterPath::cubicTo(...) ?
    By brucelamond in forum Qt Programming
    Replies: 0
    Last Post: 28th April 2011, 23:30
  2. QRegExp - get only last result
    By kabanek in forum Newbie
    Replies: 2
    Last Post: 3rd November 2010, 22:17
  3. How to display result
    By sksingh73 in forum Newbie
    Replies: 1
    Last Post: 7th June 2010, 08:39
  4. QSqlQuery return result
    By arpspatel in forum Qt Programming
    Replies: 2
    Last Post: 9th April 2010, 07:55
  5. Error in QRectF::intersects
    By lni in forum Qt Programming
    Replies: 3
    Last Post: 11th February 2009, 17:24

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
  •  
Qt is a trademark of The Qt Company.