Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Position of an object mapped relative to its parent
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();
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())));
I'm new to this, so would like some help.
Have you tried using maptFromGlobal() instead?
Simple matter of using