Capture mouse click() on QLineEdit
Solved
General and Desktop
-
Hello folks, I tried to make an event filter for capture the click mouse on a QLineEdit, I getted the code from google, but it does not work and i don't understand why. Help please
Any help will be wellcomedclass getmsg : public QWidget { Q_OBJECT public: getmsg(QWidget *parent = 0, int _maxX=0, int _maxY=0, qint8 _nMsg = 0); private: QLineEdit *askCh; bool getmsg::eventFilter(QObject *object, QEvent* event); };
getmsg::getmsg(QWidget *parent, int _maxX, int _maxY, qint8 _nMsg) : QWidget(parent),maxX(_maxX),maxY(_maxY),nMsg(_nMsg) { resize(maxX,maxY); askCh = new QLineEdit(this); askCh->installEventFilter(this); } //******************************************************** bool getmsg::eventFilter(QObject *object, QEvent *event) { if(object == askCh && event->type() == QEvent::MouseClick) { qDebug() << "You have clicked"; return false; // lets the event continue to the edit } return false; }
Tha console said
error: C2027: use of undefined type 'QEvent'
see declaration of 'QEvent'
error: C2227: left of '->type' must point to class/struct/union/generic type
error: C2065: 'MouseClick' : undeclared identifierThanks in advance
-
Add
#include <QEvent>
-
Did you add
#include <QEvent>
in the cpp file?