collidingItems() seems broken

  • Hello everybody!

    I am developing a game, and I am overriding shape() for my pixmapitem player with an ellipse to make collisions with walls smoother (independent from actual pixmap outline). I am using a factor, which determines the size of the ellipse scaled to the player's boundingRect(). When I set the factor to <=1, everything works great, the player collides with its ellipse shape (see the first and second image, where the grey area is the corner of a wall, the magenta rectangle is the boundingRect() added to the scene, and the red ellipse is the path from shape() added to the scene). However, when I set factor to >1 and it becomes bigger than the boundingRect(), and it seems that the player collides with its boundingRect() and not its shape() (see the third image).
    This observation is true for calling collidingItems() without changing the default mode (which checks collisions with shape()). I am checking collision with the border of the map in a different way, there's a RectItem around the border and all objects should be inside it, otherwise they would leave the map. For this, I am using collidesWithItem() and this works when the factor is >1 (see the fourth image).


    Can someone explain to me what am I doing wrong? Or is collidingItems() actually broken and it uses the smaller from boundingRect() and shape()?

    EDIT: I am using Qt 5.10, on Windows

    Here are some code snippets about the parts in question:

    //Player shape:

    QPainterPath Player::shape() const {
        QPainterPath path;
        QRectF r = boundingRect();
        double factor = 1.0;
        path.addEllipse(r.x()+r.width()*(1.0-factor)/2, r.y()+r.height()*(1.0-factor)/2, r.width()*factor, r.height()*factor);
        return path;

    // If this is true then I move the player back

    bool tryingToMoveOutsideTheMap = collidesWithItem(borderRectItem, Qt::ContainsItemShape) == false;

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.