Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Getting coordinate relative to QGraphicsItem on mouse click in QGraphicsView
QtWS25 Last Chance

Getting coordinate relative to QGraphicsItem on mouse click in QGraphicsView

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 367 Views
  • 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.
  • L Offline
    L Offline
    lansing
    wrote on last edited by
    #1

    I have a rectangle QGraphicsView and a QGraphicsItem inside, I want to retrieve the x-position relative to the item when I click in the view.

    For example, I have a graphicsview of 1000 px wide and a graphicsItem of 100 px wide, the item is placed at the 500 px point in the view. When I clicked on 502 px in the view, I want it to return something like a QPoint with x=2.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on last edited by Bonnie
      #2

      I'm not familiar with the graphics view framework, but from the information of doc, I think you can:
      step1. map from view to scene by QGraphicsView::mapToScene.
      step2. map from scene to item by QGraphicsItem::mapFromScene.
      I haven't found a direct mapping method from QGraphicsView to QGraphicsItem.

      L 1 Reply Last reply
      1
      • B Bonnie

        I'm not familiar with the graphics view framework, but from the information of doc, I think you can:
        step1. map from view to scene by QGraphicsView::mapToScene.
        step2. map from scene to item by QGraphicsItem::mapFromScene.
        I haven't found a direct mapping method from QGraphicsView to QGraphicsItem.

        L Offline
        L Offline
        lansing
        wrote on last edited by
        #3

        @Bonnie

        Thank you this works.

        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