Results 1 to 3 of 3

Thread: QPainter and containsPoint()

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Posts
    64

    Default QPainter and containsPoint()

    Im trying to make a widget that is 4 triangles put together to for a square, and each triangle is its own polygon... when i click in anyone of the separate triangles, its color toggles between green and red.

    I am able to get the shape drawn exactly how i want it... except now it doesnt behave like i thought it would. I reimplemented a mousePressEvent and used the .containsPoint() function in QPainter to try and compare where i clicked and what is inside the polygon. here is my code

    Qt Code:
    1. void SmokeDisplay::mousePressEvent(QMouseEvent *event)
    2. {
    3. event->accept;
    4. if (leftPolyM.containsPoint(event->pos(),Qt::WindingFill))
    5. {
    6. leftActive=!leftActive;
    7. }
    8. else if (rightPolyM.containsPoint(event->pos(),Qt::WindingFill))
    9. {
    10. rightActive=!rightActive;
    11. }
    12. else if (bottomPolyM.containsPoint(event->pos(),Qt::WindingFill))
    13. {
    14. bottomActive=!bottomActive;
    15. }
    16. else if (topPolyM.containsPoint(event->pos(),Qt::WindingFill))
    17. {
    18. topActive=!topActive;
    19. }
    20. update();
    21. }
    To copy to clipboard, switch view to plain text mode 

    and i select which color to fill the polygons in the paintEvent depending on the bool value of leftActive, rightActive etc...

    so what happens is only the rightPoly and the bottomPoly ever change, but not even when i click inside of them... the rightPoly changes when i click the left half of my topPoly and and bottom changes when i click the top half of my leftPoly... and each change when i am slightly outside of any poly...

    anyone have any suggestions or alternate methods? I attached a picture of what my widget looks like.
    Attached Images Attached Images

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.