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