Results 1 to 3 of 3

Thread: Retrieving mouseover coordinates of QGraphicsScene

  1. #1
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Retrieving mouseover coordinates of QGraphicsScene

    I have a QGraphicsView with a set QGraphicsScene. I'm trying to get the coordinates (on mouseover) of where the mouse is relative to the scene. I'm able to get the coordinates of the entire screen, but not the scene. Is there any way to accomplish this?

    This is the code I have so far, but it only returns the window coordinates:
    Qt Code:
    1. bool Form::eventFilter(QObject *o, QEvent *e)
    2. {
    3. if (o = ui.graphicsView->viewport()){
    4. QPoint a = QCursor::pos();
    5. QString coord = QString::number(a.x()) + ", " + QString::number(a.y());
    6. ui.coordLabel->setText(coord);
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Retrieving mouseover coordinates of QGraphicsScene


  3. #3
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Retrieving mouseover coordinates of QGraphicsScene

    Thanks for the tip! this is what I did incase anyone ever needs it:

    Qt Code:
    1. QPointF a = ui.graphicsView->mapToScene(ui.graphicsView->mapFromGlobal(QCursor::pos()));
    To copy to clipboard, switch view to plain text mode 

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.