I have Qgraphicsview object , I have used drawPolygons now I want check if the point x1 y1 is inside a polygon or not



  • Now I have a point I want to check if the Point (x1,y1) is inside the polygon boundary


  • Moderators

    @Qt-Enthusiast This is now the third post with the same question!
    Please stop asking same question several times!

    What is exactly the problem? QPolygon provides containsPoint() method which does exactly what you want to do:

    QPoint p(10, 10);
    if (polygon.containsPoint(p, Qt::OddEvenFill))
        qDebug() << "inside";
    else
        qDebug() << "not inside";
    


  • What is Qt::OddEvenFill) stands for ?
    Also for points on the boundary of the polygon , the containsPoint returns false . but as per my application the points on the boundary of the polygon are outside the polygon .What is the solution to fix this



  • You need to learn to use the documentation.

    http://doc.qt.io/qt-5/qt.html#FillRule-enum

    Also, beware that "for points on the boundary", are basically none-existant due to rounding errors in any floating point model. "near the boundary" is about as close as you can get.


  • Moderators

    @Qt-Enthusiast I agree with @BjornW : you should really start to read the documentation! What you asked is described there, but you are asking other people to spend their time to explain it. It is OK to ask if you do not understand the description in the documentation, but please try to read and understand the documentation first!



  • @jsulm

    My apologies for the same and I will take of the same in the future



  • @BjornW
    I went through http://doc.qt.io/qt-5/qt.html#FillRule-enum but I still have questions

    When to use Qt::OddEvenFill and when to use Qt::WindingFill . What is pros/cons using one fillRule over other



  • I don't know it any better than what was documented, sorry. Did you try the code @jsulm wrote? Does it work?



  • http://blogs.adobe.com/webplatform/2013/01/30/winding-rules-in-canvas/

    Just leave the argument omitted (defaults to odd-even)


Log in to reply