Capture mouse click() on QLineEdit

  • 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 wellcomed


    class getmsg : public QWidget
        getmsg(QWidget *parent = 0, int _maxX=0, int _maxY=0, qint8 _nMsg = 0);
        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)
        askCh = new QLineEdit(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 identifier

    Thanks in advance

  • Moderators


    #include <QEvent>

  • @yczo
    The QEvent Documentation says

    QEvent::MouseButtonPress 2 Mouse press (QMouseEvent)

  • thank you but I'am so newbie, and I don't understand that
    I tryed

    if(object == askCh && event->type() == QEvent::MouseButtonPress) {

    but It does not work :-(

  • Moderators

    Did you add

    #include <QEvent>

    in the cpp file?

  • yes, in "getmsg.h"

  • Ok, okkk Solved, I'm sorry, i forget the == on tests
    if(object == askCh && event->type() == QEvent::MouseButtonPress) {

    Thank you very much

  • @yczo

    Good to hear that it works now for you.
    Please do not forget to mark the question as Solved.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.