Results 1 to 4 of 4

Thread: mousePressEvent

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Post mousePressEvent

    Hi, I need to implement below in Widget::mousePressEvent(QmouseEvent* e)
    Qt Code:
    1. if (Qt::LeftButton == e->state() ) && (Qt::RightButton == e->state() ) ...{
    2. doSomething();
    3. }
    To copy to clipboard, switch view to plain text mode 
    bui it take only a event...is there a way? Thanks
    Regards

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: mousePressEvent

    From docs:
    This means that if you have a QEvent::MouseButtonPress or a QEvent::MouseButtonDblClick state() will not include the mouse button that's pressed. But once the mouse button has been released, the QEvent::MouseButtonRelease event will have the button() that was pressed.
    So try implementing that in mouse release event (and use e->button()) instead.

    PS. ...and how could it be "left" AND "right" same time anyway..?

  3. #3
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: mousePressEvent

    You always can init some flag when you press one button and then use it in handler for other
    a life without programming is like an empty bottle

  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: mousePressEvent

    Quote Originally Posted by jpn
    PS. ...and how could it be "left" AND "right" same time anyway..?
    If you have both buttons pressed. But the proper construction should be "e->state() & Qt::RightButton"

  5. The following user says thank you to wysota for this useful post:

    mickey (21st March 2006)

Similar Threads

  1. mousePressEvent Problem in Qt4
    By hotjava in forum Qt Programming
    Replies: 2
    Last Post: 9th November 2008, 09:29
  2. QGraphicScene MousePressEvent
    By Spitz in forum Qt Programming
    Replies: 3
    Last Post: 16th November 2007, 21:46
  3. Replies: 2
    Last Post: 1st November 2007, 08:25
  4. MousePressEvent for QTextEdit
    By anju123 in forum Qt Programming
    Replies: 9
    Last Post: 16th August 2007, 06:08
  5. Replies: 6
    Last Post: 30th April 2007, 23:59

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.