Results 1 to 4 of 4

Thread: QGraphicsScene::mouseMoveEvent Question

  1. #1
    Join Date
    May 2007
    Posts
    33
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsScene::mouseMoveEvent Question

    hi, i have a QGraphicsScene in a QGraphicsView:

    Qt Code:
    1. view = new GraphicsView( this );
    2. scene = new GraphicsScene( this );
    3. scene->setSceneRect( 0.0, 0.0, 512.0, 512.0 );
    4. scene->add....(...
    5. ....
    6. view->setScene( scene );
    7. view->show();
    To copy to clipboard, switch view to plain text mode 

    all objects added to the scene are displayed correctely, but
    Qt Code:
    1. void GraphicsScene::mouseMoveEvent( QGraphicsSceneMouseEvent *event ) {
    2. cout << " moved to: X->" << event->pos().toPoint().x();
    3. cout << " moved to: Y->" << event->pos().toPoint().y() << endl;
    4. event->accept();
    5. }
    To copy to clipboard, switch view to plain text mode 

    always results in X->0 and Y->0
    why is that so?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene::mouseMoveEvent Question

    What does:
    Qt Code:
    1. cout << " moved to: X->" << event->pos().x();
    2. cout << " moved to: Y->" << event->pos().y() << endl;
    To copy to clipboard, switch view to plain text mode 
    output?

  3. #3
    Join Date
    May 2007
    Posts
    33
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene::mouseMoveEvent Question

    ...
    moved to: X->0 moved to: Y->0
    moved to: X->0 moved to: Y->0
    moved to: X->0 moved to: Y->0
    moved to: X->0 moved to: Y->0
    ...

    :-(

  4. #4
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsScene::mouseMoveEvent Question

    Use event->scenePos()
    event->pos() is used to represent mouse coords in terms of item So it will be 0 when you use it in scene's mouse event.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

Similar Threads

  1. Access to QSqlTableModel::isDirty Question.
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 12th April 2007, 17:49
  2. Replies: 1
    Last Post: 15th March 2007, 20:45
  3. Question regarding how to paint after zoom.
    By JonathanForQT4 in forum Qt Programming
    Replies: 2
    Last Post: 26th January 2007, 15:34
  4. QThread exit()/quit() question
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 28th August 2006, 14:38

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.