Results 1 to 6 of 6

Thread: Scene Mouse Position Slightly Offline :S

  1. #1
    Join Date
    Oct 2012
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question Scene Mouse Position Slightly Offline :S

    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:
    Qt Code:
    1. mousepos.setX(ui->GraphicsMap->cursor().pos().x());
    2. mousepos.setY(ui->GraphicsMap->cursor().pos().y());
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Scene Mouse Position Slightly Offline :S

    What is ui->GraphicsMap? What is its cursor() method?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2012
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scene Mouse Position Slightly Offline :S

    Sorry, I was in a rush when i wrote out this question.
    GraphicsMap = QGraphicsView
    Cursor Method = self explanatory

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Scene Mouse Position Slightly Offline :S

    Quote Originally Posted by steadi View Post
    Cursor Method = self explanatory
    Is it? I don't see any cursor() method in QGraphicsView.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2012
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scene Mouse Position Slightly Offline :S

    Quote Originally Posted by wysota View Post
    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:
    Qt Code:
    1. ui->GraphicsView->cursor()->pos();
    To copy to clipboard, switch view to plain text mode 
    to get the position?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Scene Mouse Position Slightly Offline :S

    Quote Originally Posted by steadi View Post
    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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. view position of mouse position in GraphicsScene
    By Raghaw in forum Qt Programming
    Replies: 2
    Last Post: 23rd August 2012, 04:46
  2. QGraphics scene position
    By junix in forum Newbie
    Replies: 6
    Last Post: 17th April 2012, 03:41
  3. Cursor Position in scene
    By rogerholmes in forum Newbie
    Replies: 2
    Last Post: 12th March 2010, 15:31
  4. Replies: 0
    Last Post: 16th July 2009, 12:44
  5. Cursor scene position
    By xgoan in forum Qt Programming
    Replies: 1
    Last Post: 26th December 2006, 13:51

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.