1

I want to trigger where I click with the mouse on my QGraphicsView. Problem here: this QGraphicsView is always zoomed in. But I want to get the point relative to the whole widget and not only to the viewport. Or in other words: when I zoomed in and click on the upper left corner, the location should NOT be 0,0 (the QMousePressEvent just gives me this point). It should be the distance from there to the upper left corner of the whole sceneRectangle (or to the middle, doesn't matter). Is there any way to do this? Thanks for answers.

mep
  • 341
  • 2
  • 11
  • Have you looked into the `mapToGlobal` and `mapToParent` functions? Won't those work for you? If not; why? – Jesper Juhl Aug 02 '17 at 16:41
  • No, these give me just, what I already have. I am sorry it is not easy to explain... If I use these and click to the left upper corner, I get the same coordinates as when I zoom out a bit and click again to the left upper corner and that's the problem. I want the coordinated relative to the sceneRectangle (and these would change at the left upper corner when I zoom out) – mep Aug 02 '17 at 16:50
  • 1
    There's also `mapTo` and `mapToScene`.. sorry, just guessing here - not sure I quite get what you are trying to do. – Jesper Juhl Aug 02 '17 at 16:54
  • Oh YES!!! mapToScene works! ( or: myPoint = this->mapToScene(event->pos()) ) It gives me exactely what I want.I am trying to do this since hours... Finally I can continue. Thank you very much! PS: How can I select the comment as solution? – mep Aug 02 '17 at 17:00
  • you can't with a comment, but I'll post it as an answer in a moment. – Jesper Juhl Aug 02 '17 at 17:03

1 Answers1

2

You can do what you want with Qt's mapToScene function.

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70