Results 1 to 2 of 2

Thread: Mouse press

  1. #1

    Default Mouse press

    I want to register when the mouse is pressed and released on a QTableWidget. There are signals only for pressed, not released. Therefore I use mousePressEvent and mouseReleaseEvent instead.

    MyWidget.h
    Qt Code:
    1. protected:
    2. void mousePressEvent(QMouseEvent * event);
    3. void mouseReleaseEvent(QMouseEvent * event);
    To copy to clipboard, switch view to plain text mode 

    MyWidget.cpp
    Qt Code:
    1. void MyWidget::mousePressEvent(QMouseEvent *event)
    2. {
    3. qDebug() << "Pressed";
    4. }
    5.  
    6. void MyWidget::mouseReleaseEvent(QMouseEvent *event)
    7. {
    8. qDebug() << "Released";
    9. }
    To copy to clipboard, switch view to plain text mode 

    It prints "Released" when the left, right or middle mouse button is released over the table. However, it prints "Pressed" only when the right or middle button is pressed.

    What could be wrong? How can I register when the left button is pressed?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Mouse press

    And what is "MyWidget"? Is it a widget derived from QTableWidget?

    If MyWidget is derived from QTableWidget, it is possible that the base class event handler (QTableWidget::mousePressEvent()) is being called first and is eating the event.

    You could verify this by adding an event filter to the class that creates your MyWidget instance, and installing it on the MyWidget instance. An event filter will receive all events for the widget it is installed on -before- they are sent to the widget for handling. See QObject::installEventFilter() if you don't know how event filters work. Be sure to return false from your event filter if you want the table widget to keep working.

Similar Threads

  1. QlistView mouse press
    By dima in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2010, 15:51
  2. Problem with mouse press on QGraphicsView.
    By pastispast in forum Qt Programming
    Replies: 10
    Last Post: 13th September 2010, 06:52
  3. QGraphicsview and mouse press event
    By eva2002 in forum Qt Programming
    Replies: 6
    Last Post: 26th January 2010, 05:04
  4. Mouse press event detection
    By A.H.M. Mahfuzur Rahman in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2009, 13:08
  5. Checking for key press on mouse event
    By Cruz in forum Newbie
    Replies: 1
    Last Post: 24th January 2009, 18:18

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.