Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. When is QGraphicsSceneMouseEvent.pos() (item coordinate system) valid ? Who is picking items?
Qt 6.12 LTS is out! See what's new in the release blog

When is QGraphicsSceneMouseEvent.pos() (item coordinate system) valid ? Who is picking items?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.1k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I find that it often returns (0,0). It is not clear whether the QGraphicsView is picking graphic items, or sending mouse events to the scene even if no item contains the graphics device pointer (mouse, cursor.)

    I reimplemented the QGraphicsScene.mouseMoveEvent() handler, and I also have reimplemented QGraphicItems.contains() so that for certain graphic items, only the edges of the graphic items contain a pick point (the cursor.) I am guessing that if I had NOT reimplemented, the default handler does picking and fills in the item coordinates so that QGraphicsSceneMouseEvents are never delivered to handlers in graphic items with pos() returning (0,0)?

    It seems to me that the documentation could be clearer on this point.

    (And what use is QGraphicsSceneMouseEvent.screenPos() ? I find the view coordinates more useful, and strange that the screen coordinates are exposed.)

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Also, I find that QGraphicsItem.mapFromScene() isn't adequate for QGraphicsSceneMouseEvent.scenePos() for items that have the ItemIgnoresTransform flag set. The documentation is clear that it shouldn't be used. Thus to get from a QGraphicsSceneMouseEvent to a local (item) coordinate, it seems you must map from the scene to view:

      @pointViewCS = view.mapFromScene(event.scenePos())@

      and then the item map from view to local:

      @
      transform, isInvertible = self.deviceTransform(view.viewportTransform()).inverted()
      pointLocalCS = transform.map(pointViewCS)
      @

      The context is, I am implementing a custom control in a graphics view without using widgets. I don't want the control to scale with the view so I set ItemIgnores Transformation. But the control needs to receive mouse events and I need to work in local coordinates to implement the control.

      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
      • Unsolved