Collision of items
-
Are you using QtQuick or widgets?
And what exactly do you mean byalong the outer contour of polygon B?
Do you want to restrict the move? Or continue to move A, while the mouse is over B?
-
Are you using QtQuick or widgets?
And what exactly do you mean byalong the outer contour of polygon B?
Do you want to restrict the move? Or continue to move A, while the mouse is over B?
@Axel-Spoerl i guess what he meant is to move A around B, not across B. It is more a geometry issue than Qt problem. Override paint func in QWidget. Need to know how he draws polygons in QML.
-
Interesting problem. So A should deviate from the original draw path to avoid collision with B?
-
Are you using QtQuick or widgets?
And what exactly do you mean byalong the outer contour of polygon B?
Do you want to restrict the move? Or continue to move A, while the mouse is over B?
@Axel-Spoerl Hi,My friend.This is a question about QGraphicsItem. JoeCFD's reply is correct. Additionally, I hope to achieve that when there is a hole in ItemA that is larger than ItemB, I can drag ItemB to move within this hole, and of course, it should also be possible to move around the hole inside
.
-
Ask grok or deepseek about how
move a polygon A on a 2D plane. How to move A around polygon B, not across B in Qt widget or QML@JoeCFD Hi,Thanks for your reply.I have already implemented this function using the GJK algorithm, in fact, I just want to know if there is a way to implement this function in QT. Since QGraphicsItem has a collision function, I was wondering if QGraphicsItem has a way to achieve my goal that I don't know yet?
-
By default, Qt allows moving selected items, not just a single item. If you want to check for collisions or limit how far items can move, you’ll need to subclass QGraphicsScene and handle that logic there.
But if you only have one movable item, you can simply override the itemChange event in your item class to restrict its movement.
-
@JoeCFD Hi,Thanks for your reply.I have already implemented this function using the GJK algorithm, in fact, I just want to know if there is a way to implement this function in QT. Since QGraphicsItem has a collision function, I was wondering if QGraphicsItem has a way to achieve my goal that I don't know yet?
@DiZhu if you read the docu, you may realize that the collides funcs of QGraphicsItem use bounding boxes of items to detect collision and this may not fit your app. If you have only triangles, it might be relatively easy for you to implement more accurate methods for collision detection. But it can be tough to handle all shapes of polygons.