Results 1 to 4 of 4

Thread: GraphicsView mouse event, coordinates changing based on viewable portion

  1. #1
    Join Date
    Jun 2014
    Posts
    13
    Thanks
    1
    Qt products
    Qt5

    Default GraphicsView mouse event, coordinates changing based on viewable portion

    I'm writing a map editor and I'm having an issue with my implementation of the graphicsview control. When I click down and all of the map is in view, it works great. But when I have only part of the map in view, the mouse coordinates seem to be relative to the new area only.

    Basically when the whole map is in view 0,0 is the very top left tile. But when I have only a section in view, the top left viewable section becomes 0, 0. This creates a problem when I draw because that 0, 0 position is on the actual field, in the top left, so it draws on the top left instead. This is how I'm using the mouse coordinates:


    Qt Code:
    1. int x = event->pos().x();
    2. int y = event->pos().y();
    3.  
    4. if(x < 0 || y < 0)
    5. return;
    6.  
    7. if(x > ((activeGrid->getWidth()) - 1) || y > ((activeGrid->getHeight()) - 1))
    8. return;
    9.  
    10. x = (x) / (TILE_SIZE);
    11. y = (y) / (TILE_SIZE);
    12.  
    13. mouseX = x;
    14. mouseY = y;
    15.  
    16. emit(mouseMoved(QPoint(mouseX, mouseY)));
    To copy to clipboard, switch view to plain text mode 

    Is there a way to get the X & Y cordinates of the graphicsview as a whole and NOT relative to the section viewable?

  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: GraphicsView mouse event, coordinates changing based on viewable portion

    You didn't mention which class that is in.

    Maybe you are handling the events in the view when you want to handle scene events or vice versa.

    Cheers,
    _

  3. #3
    Join Date
    Jun 2014
    Posts
    13
    Thanks
    1
    Qt products
    Qt5

    Default Re: GraphicsView mouse event, coordinates changing based on viewable portion

    Quote Originally Posted by anda_skoa View Post
    You didn't mention which class that is in.

    Maybe you are handling the events in the view when you want to handle scene events or vice versa.

    Cheers,
    _
    The code is from my graphicsview widget. Should that be in the scene instead?

  4. #4
    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: GraphicsView mouse event, coordinates changing based on viewable portion

    Quote Originally Posted by bnosam View Post
    The code is from my graphicsview widget. Should that be in the scene instead?
    The view events are in the coordinate system of the widget, which, if I understand from your first posting, is not what you want.
    The scene's events are get the view transformations applied.

    Cheers,
    _

Similar Threads

  1. QGraphicsTextItem center based coordinates
    By mihnen in forum Qt Programming
    Replies: 3
    Last Post: 19th September 2012, 16:48
  2. Replies: 3
    Last Post: 7th January 2012, 08:38
  3. Replies: 3
    Last Post: 12th May 2010, 13:11
  4. getting mouse coordinates
    By eric in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2007, 19:34
  5. changing QLabel font size(label created on the graphicsView)
    By maverick_pol in forum Qt Programming
    Replies: 11
    Last Post: 17th August 2007, 08:36

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.