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. number of event filter calls

number of event filter calls

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 360 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.
  • I Offline
    I Offline
    IknowQT
    wrote on last edited by
    #1

    I checked the number of calls to debug in the event filter, but it came in twice. Why is it called twice?

    bool usrCntrListWidget::eventFilter(QObject* dest, QEvent* event)
    {
    	if (event->type() == QEvent::TouchBegin)
    	{
            QTouchEvent* e = static_cast<QTouchEvent*>(event);
            if (e)
            {
                if (e->touchPointStates() == Qt::TouchPointPressed)
                {
                    m_bClicked = true;
                }
                else if (e->touchPointStates() == Qt::TouchPointReleased)
                {
                    m_bClicked = false;
                }
    
                qDebug() << "eventFilter" + m_bClicked;
            }
    	}
    
        else if (event->type() == QEvent::MouseButtonPress)
        {
            QMouseEvent* e = static_cast<QMouseEvent*>(event);
            if (e->button() & Qt::LeftButton)
            {
                //if(!m_bVisibleCheckBox)
                //    QTimer::singleShot(1000, this, SLOT(GetLastTime()));
    			m_bClicked = true;
              
                //m_tPushTime->start(1000);
    
    			qDebug() << QString("MouseButtonPress : %1").arg(m_bClicked);
    		}
    	}
    
        else if (event->type() == QEvent::MouseButtonRelease)
        {
            QMouseEvent* e = static_cast<QMouseEvent*>(event);
            if (e->button() & Qt::LeftButton)
    		{
    			m_bClicked = false;
    			qDebug() << QString("MouseButtonRelease : %1");
    		}
    	}
    
        else if (event->type() == QEvent::MouseButtonDblClick)
        {
            QMouseEvent* e = static_cast<QMouseEvent*>(event);
            if (e->button() & Qt::LeftButton)
            {
                m_bClicked = false;
    
                if (m_bVisibleCheckBox)
                    VisibleCheckBox(false);
                
                qDebug() << QString("MouseButtonDblClick : %1");
            }
        }
    
    	return false;
    }
    

    e2bb01d2-2888-4b3b-bbc0-d475db269458-image.png

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Did you install an event filter ?
      On which object ?
      You should also print the object that is passed in parameter.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      I 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Did you install an event filter ?
        On which object ?
        You should also print the object that is passed in parameter.

        I Offline
        I Offline
        IknowQT
        wrote on last edited by
        #3

        @SGaist

        I changed the event filter to mouse event and it worked as I wanted.

        class usrCntrListWidget : public QListWidget
        {
        	Q_OBJECT
        
        private:
        	bool		m_bClicked;
        	bool		m_bVisibleCheckBox;
        	int			m_nCount;
        	QTimer*		m_pTimer;
        
        public:
        	usrCntrListWidget(QWidget *parent);
        	~usrCntrListWidget();
        	void	VisibleCheckBox(bool bShow);
        
        public slots:
        	void	GetLastTime();
        	void	VisibleCheckBox(QListWidgetItem* item);
        
        protected:
        	void    mousePressEvent(QMouseEvent* event) override;
        	void    mouseReleaseEvent(QMouseEvent* event) override;
        	void    mouseDoubleClickEvent(QMouseEvent* event) override;
        };
        
        
        ------------------------------- cpp -------------------------------
        void usrCntrListWidget::mousePressEvent(QMouseEvent* event)
        {
        	if (event->button() & Qt::LeftButton)
        	{
                qDebug() << "mousePressEvent";
                m_pTimer->start(1000);
            }
        }
        
        void usrCntrListWidget::mouseReleaseEvent(QMouseEvent* event)
        {
            if (event->button() & Qt::LeftButton)
            {
                qDebug() << "mouseReleaseEvent";
        
        		if (m_pTimer->isActive())
                    m_pTimer->stop();
            }
        }
        
        usrCntrListWidget::usrCntrListWidget(QWidget *parent)
        	:   m_bClicked(false),
                m_nCount(0),
                m_bVisibleCheckBox(false),
                m_pTimer(new QTimer(this))
        {
        	this->setMouseTracking(true);
        	this->viewport()->installEventFilter(this);
            this->connect(this->m_pTimer, SIGNAL(timeout()), this, SLOT(GetLastTime()));
            this->connect(this, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(VisibleCheckBox(QListWidgetItem*)));
        }
        
        void usrCntrListWidget::VisibleCheckBox(QListWidgetItem* item) 
        {
            qDebug() << "VisibleCheckBox";
        
        	usrCntrListItem* pItem = qobject_cast<usrCntrListItem*>(this->itemWidget(item));
            pItem->SetCheckVisible(!pItem->GetCheckStatus());
        }
        
        void usrCntrListWidget::mouseDoubleClickEvent(QMouseEvent* event)
        {
            if (event->button() & Qt::LeftButton)
            {
                qDebug() << "mouseDoubleClickEvent";
        
                if(m_bVisibleCheckBox)
                    VisibleCheckBox(false);
            }
        }
        

        But can you check if my method is correct?
        Others say they didn't call the base class, I don't know what the problem is

        jsulmJ 1 Reply Last reply
        0
        • I IknowQT

          @SGaist

          I changed the event filter to mouse event and it worked as I wanted.

          class usrCntrListWidget : public QListWidget
          {
          	Q_OBJECT
          
          private:
          	bool		m_bClicked;
          	bool		m_bVisibleCheckBox;
          	int			m_nCount;
          	QTimer*		m_pTimer;
          
          public:
          	usrCntrListWidget(QWidget *parent);
          	~usrCntrListWidget();
          	void	VisibleCheckBox(bool bShow);
          
          public slots:
          	void	GetLastTime();
          	void	VisibleCheckBox(QListWidgetItem* item);
          
          protected:
          	void    mousePressEvent(QMouseEvent* event) override;
          	void    mouseReleaseEvent(QMouseEvent* event) override;
          	void    mouseDoubleClickEvent(QMouseEvent* event) override;
          };
          
          
          ------------------------------- cpp -------------------------------
          void usrCntrListWidget::mousePressEvent(QMouseEvent* event)
          {
          	if (event->button() & Qt::LeftButton)
          	{
                  qDebug() << "mousePressEvent";
                  m_pTimer->start(1000);
              }
          }
          
          void usrCntrListWidget::mouseReleaseEvent(QMouseEvent* event)
          {
              if (event->button() & Qt::LeftButton)
              {
                  qDebug() << "mouseReleaseEvent";
          
          		if (m_pTimer->isActive())
                      m_pTimer->stop();
              }
          }
          
          usrCntrListWidget::usrCntrListWidget(QWidget *parent)
          	:   m_bClicked(false),
                  m_nCount(0),
                  m_bVisibleCheckBox(false),
                  m_pTimer(new QTimer(this))
          {
          	this->setMouseTracking(true);
          	this->viewport()->installEventFilter(this);
              this->connect(this->m_pTimer, SIGNAL(timeout()), this, SLOT(GetLastTime()));
              this->connect(this, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(VisibleCheckBox(QListWidgetItem*)));
          }
          
          void usrCntrListWidget::VisibleCheckBox(QListWidgetItem* item) 
          {
              qDebug() << "VisibleCheckBox";
          
          	usrCntrListItem* pItem = qobject_cast<usrCntrListItem*>(this->itemWidget(item));
              pItem->SetCheckVisible(!pItem->GetCheckStatus());
          }
          
          void usrCntrListWidget::mouseDoubleClickEvent(QMouseEvent* event)
          {
              if (event->button() & Qt::LeftButton)
              {
                  qDebug() << "mouseDoubleClickEvent";
          
                  if(m_bVisibleCheckBox)
                      VisibleCheckBox(false);
              }
          }
          

          But can you check if my method is correct?
          Others say they didn't call the base class, I don't know what the problem is

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @IknowQT In this thread https://forum.qt.io/topic/132824/how-to-use-mouse-events-and-signals-together I gave you a link which explains how to implement event handlers. Did you read it?

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

          1 Reply Last reply
          2

          • Login

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