Results 1 to 2 of 2

Thread: How to get the exact location from a click on the qgraphicsscene

  1. #1
    Join Date
    Mar 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Question How to get the exact location from a click on the qgraphicsscene

    Hi, I am writing codes to load in image from a file and did some edits on this image(change some pixels' value), zoomed in or zoomed out and then save the image.
    Also, I want to know the location in the original image associated to a click on the qgraphicsscen. Up till now, I can not find any function useful.

    My codes for loading image:
    qgraphicsscene = myqgraphicsview->getScene();
    qgraphicsscene->setSceneRect(image->rect());
    myqgraphicsview->setScene(qgraphicsscene);
    qgraphicsscene->addPixmap(QPixmap::fromImage(*image));

    My codes for editing:
    mousePressEvent(QMouseEvent * e){
    QPointF pt = mapToScene(e->pos());
    scene->addEllipse(pt.x()-1, pt.y()-1, 2.0, 2.0,
    QPen(), QBrush(Qt::SolidPattern));}
    I want to know the relationship between e->pos() and the exact location in the original image.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get the exact location from a click on the qgraphicsscene

    Lets see: you have the point in scene coordinates. QGraphicsItem has a method called mapFromScene().

    I wonder if that could be used to map the point to item coordinates of the pixmap item. What do you think?

    Cheers,
    _

Similar Threads

  1. Replies: 0
    Last Post: 9th October 2012, 20:47
  2. QGraphicsScene with scaled item freezes application on click
    By FlashMuller in forum Qt Programming
    Replies: 2
    Last Post: 31st January 2011, 13:51
  3. Replies: 2
    Last Post: 19th October 2010, 06:33
  4. Send a mouse right click into QGRaphicsScene
    By jano_alex_es in forum Newbie
    Replies: 2
    Last Post: 11th March 2010, 14:47
  5. QGraphicsScene Click / Double Click
    By philentropist in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2007, 04:32

Tags for this Thread

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.