Results 1 to 2 of 2

Thread: coordinate problem

  1. #1
    Join Date
    Nov 2008
    Posts
    5

    Question coordinate problem

    I encounter a coordinate problem when I reimplement the QGraphicsView.

    I derive from the QGraphicsView, to get the cursor position in the pixmap coordinate, which is on the scene( at center, i guess, cause I simply scene()->addPixmap(..) ).

    void MyView::mousePressEvent (QMouseEvent *event)
    {
    ...
    QPointF cp = mapToScene(event->pos());
    ...
    }

    As I use the following codes to check the pixmap's location in scene coordinate
    QGraphicsPixmapItem *item = (QGraphicsPixmapItem *)scene()->itemAt(0, 0);
    QPointF offset1 = item->offset();
    QPointF scePos = item->scenePos();

    both offset1 and scePos is (0, 0)
    So I think that the item is at scene's center, while the pixmap on it is at the item's center too.
    Then the cp from the mousePressEvent should equal to its coordinate in pixmap, right ?
    However, tha fact seems incorrect, could you give me any advice, 3ks.

  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: coordinate problem

    The item is at scene's origin, not its centre (unless they are equal). The view (widget), the viewport (child of the view), the scene and the items all have different coordinate systems so you can't just take a position in the view's coordinate system and use it with methods that expect one of the other coordinate systems. If you want to do that, you have to map between the systems with appropriate methods available throughout the graphics view API.
    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. Replies: 19
    Last Post: 3rd April 2009, 23:17
  2. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  3. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  4. problem with paint and erase in frame
    By M.A.M in forum Qt Programming
    Replies: 9
    Last Post: 4th May 2008, 20:17
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.