PDA

View Full Version : Scene Mouse Position Slightly Offline :S



steadi
20th October 2012, 16:20
Hello,

Sorry for the short post but I am on my linux laptop. So, here is the problem that I am hoping someone could help me out with: In a previous post, I asked about placing an item where the mouse cursor is by using a scene. After finally getting this to work, I was able to place items but the mouse coordinates where way off to the right.

Here is the code that I am using:


mousepos.setX(ui->GraphicsMap->cursor().pos().x());
mousepos.setY(ui->GraphicsMap->cursor().pos().y());


This works but the items are placed wayy off from the coordinates.

So, is this code correct or is there a more precise way of doing this?
Sorry again for this being under-detailed and short but I am using my laptop and have somewhere to be.

Thanks guys,
Matt

wysota
20th October 2012, 18:42
What is ui->GraphicsMap? What is its cursor() method?

steadi
23rd October 2012, 03:41
Sorry, I was in a rush when i wrote out this question.
GraphicsMap = QGraphicsView
Cursor Method = self explanatory

wysota
23rd October 2012, 08:37
Cursor Method = self explanatory
Is it? I don't see any cursor() method in QGraphicsView.

steadi
23rd October 2012, 14:05
Is it? I don't see any cursor() method in QGraphicsView.
Oh. I am looking at my code now and there most certainly is a cursor method. I am almost certain. Then you would
use something like:

ui->GraphicsView->cursor()->pos();
to get the position?

wysota
23rd October 2012, 14:43
Oh. I am looking at my code now and there most certainly is a cursor method. I am almost certain.
I don't know this method, I have no idea what it does therefore I can't help you. The only cursor() method I know is QWidget::cursor() that returns an enum representing the shape of the cursor.

Usuallly you get cursor position from mouse events and map it to the proper coordinate space (scene or the view's viewport).