title: How to add a QMouseEvent to an EventFilter?
body: <p>I added an EventFilter to a QCompleter because I had the same problem as <a href="https://stackoverflow.com/q/11865129/8450121">this</a> person. </p>
  
  <p>Now I want to add a left mouse button event if an item is clicked from the PopupCompletion.
  I tried but I have no idea if I'm on the right track because im new to Qt.</p>
  
  <h2>eventfilter.h</h2>
  
  <pre><code>class EventFilter : public QObject
  {
     Q_OBJECT
  public:
     EventFilter(QLineEdit* lineEdit, QObject* parent = NULL)
        :QObject(parent)
        ,mLineEdit(lineEdit)
     { }
     virtual ~EventFilter()
     { }
  
     bool eventFilter(QObject* watched, QEvent* event);
  
  private:
     QLineEdit* mLineEdit;
  };
  </code></pre>
  
  <h2>eventfilter.cpp</h2>
  
  <pre><code>#include "eventfilter.h"
  
  bool EventFilter::eventFilter(QObject* watched, QEvent* event)
  {
      QAbstractItemView* view = qobject_cast&lt;QAbstractItemView*&gt;(watched);
      if (event-&gt;type() == QEvent::KeyPress)
      {
          QKeyEvent *keyEvent = static_cast&lt;QKeyEvent*&gt;(event);
          if (keyEvent-&gt;key() == Qt::Key_Return ||
              keyEvent-&gt;key() == Qt::Key_Enter ||
              keyEvent-&gt;key() == Qt::Key_Tab)
          {
              mLineEdit-&gt;clear();
              mLineEdit-&gt;setFocus();
              view-&gt;hide();
              return true;
          }
      }
      if (event-&gt;type() == QEvent::MouseButtonPress)
      {
          QMouseEvent *mouseEvent = static_cast&lt;QMouseEvent*&gt;(event);
          if (mouseEvent-&gt;button() == Qt::LeftButton)
          {
              mLineEdit-&gt;clear();
              mLineEdit-&gt;setFocus();
              view-&gt;hide();
              return true;
          }
      }
      return false;
  }
  </code></pre>
  
  <h2>mainwindow.h</h2>
  
  <pre><code>#include "eventfilter.h"
  
  class QCompleter;
  class QLabel;
  class QLineEdit;
  class QWidget;
  
  class MainWindow : public QMainWindow
  {
      Q_OBJECT
  
  public:
      MainWindow(QWidget *parent = 0);
  
  private:
      void createMenu();
      QAbstractItemModel *modelFromFile(const QString&amp; fileName);
  
      QCompleter *completer;
      QLabel *contentsLabel;
      QLineEdit *lineEdit;
      QWidget *widgetBox;
  };
  </code></pre>
  
  <h2>mainwindow.cpp</h2>
  
  <pre><code>#include "mainwindow.h"
  
  completer = new QCompleter(this);
  completer-&gt;setModel(modelFromFile(":/resources/wordlist.txt"));
  completer-&gt;setModelSorting(QCompleter::CaseInsensitivelySortedModel);
  lineEdit-&gt;setCompleter(completer);
  EventFilter *filter = new EventFilter(lineEdit);
  completer-&gt;popup()-&gt;installEventFilter(filter);
  </code></pre>