Qt 5.10 Book Examples
MouseFilter.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // MouseFilter.cpp
3 // ======================================================================
4 // This file is a part of the book
5 // "Qt 5.10 Professional programming with C++"
6 // http://qt-book.com
7 // ======================================================================
8 // Copyright (c) 2017 by Max Schlee
9 // ======================================================================
10 
11 #include <QtWidgets>
12 #include "MouseFilter.h"
13 
14 // ----------------------------------------------------------------------
15 MouseFilter::MouseFilter(QObject* pobj/*= 0*/)
16  : QObject(pobj)
17 {
18 }
19 
20 // ----------------------------------------------------------------------
21 /*virtual*/bool MouseFilter::eventFilter(QObject* pobj, QEvent* pe)
22 {
23  if (pe->type() == QEvent::MouseButtonPress) {
24  if (static_cast<QMouseEvent*>(pe)->button() == Qt::LeftButton) {
25  QString strClassName = pobj->metaObject()->className();
26  QMessageBox::information(0, "Class Name", strClassName);
27  return true;
28  }
29  }
30  return false;
31 }
virtual bool eventFilter(QObject *, QEvent *)
Definition: MouseFilter.cpp:21
MouseFilter(QObject *pobj=0)
Definition: MouseFilter.cpp:15