More like this. You must test for the objects you're installing the filter for.
Qt Code:
  1. bool MWin::eventFilter(QObject* object, QEvent* event) {
  2. if(event->type() == QEvent::ContextMenu &&
  3. ( object == fileToolbar || object == modeToolBar ... ) ) {
  4. QContextMenuEvent* mevent = static_cast<QContextMenuEvent *>(event);
  5. if(mevent->reason() == QContextMenuEvent::Mouse) {
  6. qDebug("I have blocked the context menu.");
  7. return true;
  8. } else
  9. return false;
  10. }
  11. else
  12. return QObject::eventFilter(object, event);
  13. }
To copy to clipboard, switch view to plain text mode 


Regards