Results 1 to 3 of 3

Thread: How to get mouse press events out from a QTableWidget?

  1. #1
    Join Date
    Jan 2008
    Posts
    14
    Thanks
    5

    Question How to get mouse press events out from a QTableWidget?

    How to get mouse press events out from a QTableWidget which is part of another widget?

    I am using event filter and installEventFilter method. But it can only get mousepress event when I click the very edge of the QTableWidget object.

    The interesting thing is that the key-pressing events and wheel events are always caught by the code.

    Anybody knows how to deal with this? Thanks!

    Code is:
    Qt Code:
    1. // install event filter for tablewidget
    2. tableWidget->installEventFilter(this);
    3.  
    4. bool AotfFilterGui::eventFilter( QObject *object, QEvent *event )
    5. {
    6. // firstly, check whether the object is the QTableWidget and if it's a mouse press event
    7. if (object == tableWidget)
    8. if( event->type() == QEvent::MouseButtonPress)
    9. { // if yes, we need to cast the event into a QMouseEvent type
    10. QMouseEvent *pMouseEvent = static_cast<QMouseEvent *>(event);
    11. // check whether it's mid button pressed
    12. /*if (pMouseEvent->button() == Qt::MidButton)
    13. {*/
    14. //do the processing and return true
    15. textBrowserErrorInfo->setText(tr("clicked"));
    16. return true;
    17. //}
    18. }
    19. else if (event->type() == QEvent::KeyPress) {
    20. QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
    21. textBrowserErrorInfo->setText(tr( "Ate key press: " + keyEvent->text()));
    22. return true;
    23. }
    24. return QWidget::eventFilter(object, event);
    25. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to get mouse press events out from a QTableWidget?

    Install the filter on the table's viewport widget and not the table itself.

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

    Ran (2nd April 2008)

  4. #3
    Join Date
    Jan 2008
    Posts
    14
    Thanks
    5

    Default Re: How to get mouse press events out from a QTableWidget?

    Good point! wysota! It solved my question easily. Thanks a lot

Similar Threads

  1. Weird behaviour of mouse events and QMenu pop-ups
    By Ishark in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 08:46
  2. Handling Mouse Events of a parent widget
    By dvmorris in forum Qt Programming
    Replies: 2
    Last Post: 28th March 2007, 19:44
  3. Re-implement mouse events of QTextEdit
    By Ankitha Varsha in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2006, 17:55
  4. mouse moving don't produce mouse events
    By coralbird in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2006, 07:13
  5. QStackerWidget and mouse events
    By high_flyer in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2006, 20:25

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.