Results 1 to 3 of 3

Thread: QGraphicsView, QGraphicsScene item coordinates in scene

  1. #1
    Join Date
    May 2007
    Posts
    33
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsView, QGraphicsScene item coordinates in scene

    Hi,

    i have some trouble retrieving an item's position in scene coordinates.
    currently the code looks like:

    Qt Code:
    1. void view::mousePressEvent(QMouseEvent* event)
    2. {
    3. if (event->button()==Qt::LeftButton)
    4. {
    5. Vertex::Vertex* vertex = new Vertex::Vertex(QRect(event->x(), event->y(), 2, 2));
    6. vertex->setZValue(3);
    7. m_scene->addItem(vertex); // QGraphicsScene*
    8. std::cout << "Pos: " << vertex->pos().x() << " : " << vertex->pos().y() << std::endl;
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    but pos() always returns 0:0. i have read the documentation and tried a lot of things (setPos,mapToScene, scenePos..) but always retrieve a wrong or zero position.

    which function do i have to call to retreive the coordinates set by event->x(), event->y() ?

    thanks in advance

  2. #2
    Join Date
    May 2007
    Posts
    33
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView, QGraphicsScene item coordinates in scene

    can someone help me?

  3. #3
    Join Date
    Dec 2010
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QGraphicsView, QGraphicsScene item coordinates in scene

    use mouseEvent->scenePos().rx() and mouseEvent->scenePos().ry() instead of mouseEvent->pos()

Similar Threads

  1. QGraphicsView/Scene/Item Questions
    By SixDegrees in forum Qt Programming
    Replies: 0
    Last Post: 25th August 2010, 23:41
  2. Problem with QGraphicsView/Scene coordinates
    By Andrewshkovskii in forum Newbie
    Replies: 12
    Last Post: 19th October 2009, 10:41
  3. Replies: 1
    Last Post: 10th September 2009, 13:33
  4. QGraphicsView: restrict bbox of Item to bbox of scene?
    By piquadrat in forum Qt Programming
    Replies: 0
    Last Post: 2nd April 2009, 13:38
  5. Replies: 1
    Last Post: 26th September 2006, 05:38

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.