PDA

View Full Version : GraphicsView mouse event, coordinates changing based on viewable portion



bnosam
22nd July 2014, 20:06
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:



int x = event->pos().x();
int y = event->pos().y();

if(x < 0 || y < 0)
return;

if(x > ((activeGrid->getWidth()) - 1) || y > ((activeGrid->getHeight()) - 1))
return;

x = (x) / (TILE_SIZE);
y = (y) / (TILE_SIZE);

mouseX = x;
mouseY = y;

emit(mouseMoved(QPoint(mouseX, mouseY)));

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

anda_skoa
23rd July 2014, 06:45
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,
_

bnosam
24th July 2014, 05:52
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?

anda_skoa
24th July 2014, 12:23
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,
_