Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Position of an object mapped relative to its parent

Position of an object mapped relative to its parent

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 4.9k 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.
  • S Offline
    S Offline
    starbearer
    wrote on last edited by
    #1

    I have a widget with several objects in it.
    The position of the objects inside is calculated based on its relative position to its parent.
    I use that position to execute my mouse right click.

    Unfortunately when I scroll up and down inside the main widget itself, and right click on an object inside, the menu does not appear where I click, but somewhere else, based perhaps on where the object would have been earlier had I not moved the main widget..

    Please suggest a workaround. I'm new at this.

    @QGraphicsScene *parentScene = this->scene();
    //Get parent views
    QList<QGraphicsView *> parentViewList = parentScene->views();
    qDebug()<<parentViewList.at(0);
    QPoint viewPos = parentViewList.at(0)->mapToGlobal(QPoint(event->pos().x(),event->pos().y()));

    //int x = this->pos().x() + viewPos.x();
    //int y = this->pos().y() + viewPos.y();

    menu.exec(QPoint((this->pos().x() + viewPos.x()),(this->pos().y() + viewPos.y())));
    }
    @

    Thank you.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      starbearer
      wrote on last edited by
      #2

      Bump..

      Anyone, please?
      I'm new to this, so would like some help.
      Thank you.

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        Have you tried using maptFromGlobal() instead?

        (Z(:^

        1 Reply Last reply
        0
        • S Offline
          S Offline
          starbearer
          wrote on last edited by
          #4

          Solved it.
          Simple matter of using

          exec(QCursor::pos());

          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