Results 1 to 3 of 3

Thread: Problem with QGraphicsScene mouse move event

  1. #1
    Join Date
    Apr 2012
    Posts
    7
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Problem with QGraphicsScene mouse move event

    Hello,

    I re-implement mouse event handlers in a subclass of QGraphicsScene and have a problem with the mouseMoveEvent() function.

    The following code works (i.e. when I press the left/middle/right buttons, hold and move, I have the text displayed):
    Qt Code:
    1. void Scene::mouseMoveEvent(QGraphicsSceneMouseEvent* e)
    2. {
    3. std::cout<<"hehe"<<std::endl;
    4. }
    To copy to clipboard, switch view to plain text mode 

    but the following does not (nothing happens even if I press the left button):
    Qt Code:
    1. void Scene::mouseMoveEvent(QGraphicsSceneMouseEvent* e)
    2. {
    3. if(e->button()==Qt::LeftButton) std::cout<<"hehe"<<std::endl;
    4. }
    To copy to clipboard, switch view to plain text mode 

    The following code also works
    Qt Code:
    1. void Scene::mousePressEvent(QGraphicsSceneMouseEvent* e){
    2. if(e->button()==Qt::LeftButton) std::cout<<"hehe"<<std::endl;
    3. }
    To copy to clipboard, switch view to plain text mode 

    Hope it's not a bug of Qt and somebody can help.
    Thank you so much.

  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: Problem with QGraphicsScene mouse move event

    QGraphicsSceneMouseEvent::button() returns the mouse button that causes the event to happen. Since mouse movement is not related to pressing a mouse button, button() probably returns Qt::NoButton. Try this instead:

    Qt Code:
    1. if(e->buttons() & Qt::LeftButton) { ... }
    To copy to clipboard, switch view to plain text mode 
    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. The following user says thank you to wysota for this useful post:

    Nesbit (22nd April 2012)

  4. #3
    Join Date
    Apr 2012
    Posts
    7
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem with QGraphicsScene mouse move event

    Works like a charm. Thanks, wysota

Similar Threads

  1. Replies: 3
    Last Post: 7th January 2012, 09:38
  2. QAbstractItemView not calling mouse move event function
    By sagirahmed in forum Qt Programming
    Replies: 0
    Last Post: 5th July 2010, 11:26
  3. Problem in Move Move Event Handler.
    By redgoof in forum Qt Programming
    Replies: 0
    Last Post: 7th April 2010, 12:45
  4. mouse move event filtering in PyQt4
    By lucaf in forum Qt Programming
    Replies: 1
    Last Post: 4th April 2009, 15:53
  5. Mouse Move Event
    By merry in forum Newbie
    Replies: 5
    Last Post: 3rd June 2007, 07:26

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.