Results 1 to 2 of 2

Thread: QGraphicsView coordinate to QGraphicsScene

  1. #1
    Join Date
    Jul 2016
    Posts
    19
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QGraphicsView coordinate to QGraphicsScene

    Hello,

    In my custom QGraphicsScene class, I display the following two values :

    Qt Code:
    1. void MainScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
    2. {
    3. qDebug()<<views()[0]->mapToScene(event->screenPos());
    4. qDebug()<<event->scenePos(); // not equal to the previous value
    5. QGraphicsScene::contextMenuEvent(event);
    6. }
    To copy to clipboard, switch view to plain text mode 

    I don't understand why the two values are different. How can I map event->screenPos() to scene coordinates correctly ?

    Thank you

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

    Default Re: QGraphicsView coordinate to QGraphicsScene

    If you look at the method names, and their documentation, then you'll notice that you are trying to map a "screen pos" into the scene using a method of the view.
    So unless your view has no decoration and is located at 0/0 of the screen, there will be offset.

    But why do you need this in the first place, QGraphicsContextMenuEvent has a "scene pos" getter already?

    Cheers,
    _

Similar Threads

  1. QGraphicsScene Coordinate System
    By grayfox in forum Qt Programming
    Replies: 4
    Last Post: 27th February 2016, 21:34
  2. Replies: 9
    Last Post: 2nd July 2014, 12:21
  3. QGraphicsView coordinate system
    By roband915 in forum Qt Programming
    Replies: 15
    Last Post: 5th December 2013, 07:58
  4. Replies: 8
    Last Post: 8th May 2012, 00:51
  5. QGraphicsView coordinate system
    By been_1990 in forum Qt Programming
    Replies: 7
    Last Post: 2nd November 2010, 17:21

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.