Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Colliding: mapToScene seems not to work
Forum Updated to NodeBB v4.3 + New Features

Colliding: mapToScene seems not to work

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 627 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rhadel
    wrote on last edited by
    #1

    I'am trying to handle collision between an item that is child of another one (its main item), with an individual item.

    Both have set:

    @
    this->setFlags(QGraphicsItem::ItemClipsToShape);
    @

    If collision is done, then I want to check if one point of the children shape is inside the other' shape:

    @
    QPointF pointC = cable->getCableArrowPoint();
    QPainterPath path = this->shape();
    path = this->mapToScene(path);
    pointC = cable->mapToScene(pointC);
    qDebug() << "Path: " << path << " and point: " << pointC;
    if (path.contains(pointC)){
    connected.append(cable);
    cable->connectedWith = this;
    cable->ONLINE = true;
    }else{
    disconnectCable(cable);
    cable->ONLINE = false;
    cable->connectedWith = 0;
    }
    @

    But its really strange: in scene, I can see how the pointC is inside (graphically), but @if (path.contains(pointC))@ is false.

    Collision is called, but the point is not inside the shape!! Even if I can see graphically it is!!!! qDebug writes following lines:

    @
    Path: QPainterPath: Element count=5
    -> MoveTo(x=251, y=312.75)
    -> LineTo(x=263, y=312.75)
    -> LineTo(x=263, y=372.25)
    -> LineTo(x=251, y=372.25)
    -> LineTo(x=251, y=312.75)
    and point: QPointF(266, 330)
    @

    Please, can you help me? Why "x" seems being misplaced? maybe "contains." or mapToScene? I've used these functions with other items (w/o ancestors) and they work fine!

    Thank you.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved