Results 1 to 4 of 4

Thread: pyqt qgraphicsView: Get coordinate from image

  1. #1
    Join Date
    Sep 2012
    Location
    Ankara
    Posts
    15
    Thanks
    3
    Qt products
    Platforms
    Unix/X11

    Unhappy pyqt qgraphicsView: Get coordinate from image

    Hi everyone.
    There is a qgraphicsView and I made zooming enable with scroll ball. Now I want get coordinates when I click on it. However on zooming coordinates should change and I want it to return coordinates from image. Is it possible? Here my code:

    Qt Code:
    1. def display(self, FilePath, displayDevice):
    2. if os.path.isfile(FilePath):
    3. scene = QtGui.QGraphicsScene()
    4. scene.addPixmap(QtGui.QPixmap(FilePath))
    5. displayDevice.setScene(scene)
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. def zoom(self, display, val):
    2. display.scale(val, val)
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Dec 2012
    Posts
    90
    Thanks
    5
    Thanked 20 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: pyqt qgraphicsView: Get coordinate from image

    You can take click coordinates on the view, and then use display.mapToScene to get scene coordinates, I think it should be aware of scaling/rotating etc.

  3. #3
    Join Date
    Sep 2012
    Location
    Ankara
    Posts
    15
    Thanks
    3
    Qt products
    Platforms
    Unix/X11

    Default Re: pyqt qgraphicsView: Get coordinate from image

    Have you any example?
    I'm a newbie.

  4. #4
    Join Date
    Dec 2012
    Posts
    90
    Thanks
    5
    Thanked 20 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: pyqt qgraphicsView: Get coordinate from image

    Well, I'll try, but since I'm not very familiar with pyqt, expect it to be somewhat flaky
    You'll need to overload mouse event handler, so you'll need custom graphics view
    Qt Code:
    1. class CustomGraphicsView(QGraphicsView):
    2. def mousePressEvent(self, mouse_evt):
    3. point = self.mapToScene (mouse_evt.pos)
    To copy to clipboard, switch view to plain text mode 
    And in point you'll get point in scene coords. Of course you should declare your view as CustomGraphicsView.

Similar Threads

  1. QGraphicsView coordinate system
    By roband915 in forum Qt Programming
    Replies: 15
    Last Post: 5th December 2013, 06:58
  2. QGraphicsView coordinate system
    By edxxgardo in forum Qt Programming
    Replies: 3
    Last Post: 12th July 2011, 14:38
  3. QGraphicsView coordinate system
    By been_1990 in forum Qt Programming
    Replies: 7
    Last Post: 2nd November 2010, 16:21
  4. QGraphicsView Framework coordinate mapping problem
    By zgulser in forum Qt Programming
    Replies: 1
    Last Post: 14th September 2009, 12:30
  5. Replies: 1
    Last Post: 9th April 2009, 14:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.