Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Capture mouse click() on QLineEdit
Forum Updated to NodeBB v4.3 + New Features

Capture mouse click() on QLineEdit

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 4.9k Views 1 Watching
  • 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.
  • yczoY Offline
    yczoY Offline
    yczo
    wrote on last edited by yczo
    #1

    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_T 1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Add

      #include <QEvent>
      

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

      1 Reply Last reply
      1
      • yczoY 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_T Offline
        the_T Offline
        the_
        wrote on last edited by
        #3

        @yczo
        The QEvent Documentation says

        QEvent::MouseButtonPress 2 Mouse press (QMouseEvent)

        -- No support in PM --

        1 Reply Last reply
        1
        • yczoY Offline
          yczoY Offline
          yczo
          wrote on last edited by yczo
          #4

          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
          0
          • jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Did you add

            #include <QEvent>
            

            in the cpp file?

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

            1 Reply Last reply
            0
            • yczoY Offline
              yczoY Offline
              yczo
              wrote on last edited by
              #6

              yes, in "getmsg.h"

              1 Reply Last reply
              0
              • yczoY Offline
                yczoY Offline
                yczo
                wrote on last edited by
                #7

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

                Thank you very much

                the_T 1 Reply Last reply
                0
                • yczoY yczo

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

                  Thank you very much

                  the_T Offline
                  the_T Offline
                  the_
                  wrote on last edited by
                  #8

                  @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
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved