Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved Capture mouse click() on QLineEdit

    General and Desktop
    3
    8
    4083
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • yczo
      yczo last edited by yczo

      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

      //getmsg.h

      class 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.cpp

      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 identifier

      Thanks in advance

      the_ 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion last edited by

        Add

        #include <QEvent>
        

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 1
        • the_
          the_ @yczo last edited by

          @yczo
          The QEvent Documentation says

          QEvent::MouseButtonPress 2 Mouse press (QMouseEvent)

          -- No support in PM --

          1 Reply Last reply Reply Quote 1
          • yczo
            yczo last edited by yczo

            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 :-(

            1 Reply Last reply Reply Quote 0
            • jsulm
              jsulm Lifetime Qt Champion last edited by

              Did you add

              #include <QEvent>
              

              in the cpp file?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply Reply Quote 0
              • yczo
                yczo last edited by

                yes, in "getmsg.h"

                1 Reply Last reply Reply Quote 0
                • yczo
                  yczo last edited by

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

                  Thank you very much

                  the_ 1 Reply Last reply Reply Quote 0
                  • the_
                    the_ @yczo last edited by

                    @yczo

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

                    -- No support in PM --

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post