c++ - Can not map QGraphicsView coordinate to QGraphicsScene -
I have a QGraphicsScene in QGraphicsView that loaded an image. My app lets the user comment on this image so that I can get the coordination information of the user's annotation area of this image. To be more sensible, let me create this picture:
< / P>
What do I want to know about exact coordination based on image coordinates, because I add pixmap to this scene, I think there is only one coordinate system in image and view. But, there are different coordinates in the QGraphicsView and the view, as the picture shows, and they separate 5pix width and 1pix height in their computer (is this always?).
I use the function, but I do not get the correct coordinate information.
I post some code here.
view = new QGraphicsScene (); View- & gt; AddPixemPitim; UI-> Graphicsview-> Setscan (scene); Zero MainWindow :: mousePressEvent (QMouseEvent * event) {if ((event-> button () == Qt :: LeftButton) and amp; amp; amp; amp; amp; amp; amp; amp; ; Amp; amp; Start; Annotation) {....... QPointF MousePoint = ui- & gt; Graphics view - & gt; MapToScene (Event & gt; Condition ()); QDebug () & lt; & Lt; Mousepoint; }} When I click on the top-left corner of the image, I hope I can get (0,0), but instead I (5,1) get.
Please help me
Solution:
I think the IFJI is right to capture my main window mousrpressEvent and when I see an image in the scene Load, I can see the ui-> graphicsView-> gt; AdjustSize (); , then I think that & amp; Views share the same coordinate system, am I right? For this reason, I update this image:
Now, I get tips for Ecziz. I install an event filter on the view, and now the coordinate view of MouseClick & amp; is based on the view Thank you.
I think the problem here is that your mousepress event is your main window, and not actual QGraphicsView MousePressEvent is giving you coordinates for your window, it includes any range or decoration.
To resolve this, you can sub-class a CUFix scene and thereby handle the mousepress invitation in the same way as your mainwondo
A quick but probably less attractive solution would be to install an event filter on QGraphicsView. To do this, use the method of QObject installEventFilter.
Comments
Post a Comment