Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. TouchBegin through childMouseEventFilter issue

TouchBegin through childMouseEventFilter issue

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 203 Views
  • 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.
  • A Offline
    A Offline
    Andrea Iuliano
    wrote on last edited by
    #1

    Hi all.

    I'm having an issue regarding input detection: the QEvent::TouchBegin comes from the mouse call

    bool QQuickItem::childMouseEventFilter(QQuickItem *item, QEvent *event)
    

    instead of the touch one

    void QQuickItem::touchEvent(QTouchEvent *event)
    

    Following the implementation details.

    I've got two items, with parent-child hierarchy:

    class MyRootWindowQML : public QQuickView {
    public:
        MyRootWindowQML(QWindow* _wdw) : QQuickView(_wdw) {}
    protected:
        bool event(QEvent *ev);
    };
    
    bool MyRootWindowQML::event(QEvent *ev) {
        QEvent::Type type = ev->type();
    
        if (type >= 194 && type <= 196)
            HCE::Logger(HCE::TEST_LEVEL, __PRETTY_FUNCTION__) << "touchType=" << type << std::endl;
    
        ...
    
        return QQuickView::event(ev);
    }
    
    class MyChildQQuickItem : public QQuickItem {
        Q_OBJECT
    
        ...
    }
    
    MyChildQQuickItem::MyChildQQuickItem(QQuickItem* parent) {
            ...
    	QQuickItem::setParentItem( parent );
    	QQuickItem::setPosition( QPointF(0.0, 0.0) );
    	QQuickItem::setSize(QSizeF( parent->width(), parent->height()));
    	QQuickItem::setFlag( QQuickItem::ItemHasContents );
    	QQuickItem::setEnabled(true);
    	QQuickItem::setAcceptedMouseButtons(Qt::AllButtons);
    	QQuickItem::setAcceptHoverEvents(true);
    	QQuickItem::setFiltersChildMouseEvents(true);
    	QQuickItem::setAcceptTouchEvents(true);
    }
    
    

    The child one is the one who handles the input events and it exposes the methods to do it:

    bool MyChildQQuickItem::childMouseEventFilter(QQuickItem *item, QEvent *event) {
    	switch( event->type() ){
    		case QEvent::MouseButtonPress:
    			mousePressEvent(static_cast<QMouseEvent*>(event));
    			break;
    		case QEvent::MouseMove:
    			mouseMoveEvent(static_cast<QMouseEvent*>(event));
    			break;
    		case QEvent::MouseButtonRelease:
    			mouseReleaseEvent(static_cast<QMouseEvent*>(event));
    			break;
    		case QEvent::MouseButtonDblClick:
    			mouseDoubleClickEvent(static_cast<QMouseEvent*>(event));
    			break;
    		case QEvent::TouchBegin:
    		case QEvent::TouchUpdate:
    		case QEvent::TouchEnd:
    		case QEvent::TouchCancel:
            	HCE::Logger(HCE::WARNING_LEVEL, __PRETTY_FUNCTION__) << "TouchEvent comes from childMouseEventFilter: touchType=" << event->type() << std::endl;
    			touchEvent(static_cast<QTouchEvent*>(event)); //My workaround
    			break;
    		default:
            	HCE::Logger(HCE::ERROR_LEVEL, __PRETTY_FUNCTION__) << "Uknown mouse event receved: eventType=" << event->type() << std::endl;
    	}
    	return true;
    }
    
    
    void MyChildQQuickItem::mousePressEvent(QMouseEvent *event){
    	HCE::Logger(HCE::TEST_LEVEL, __PRETTY_FUNCTION__) << "touchType=" << event->type() << std::endl;
    	...
    }
    
    
    void MyChildQQuickItem::mouseMoveEvent(QMouseEvent *event){
    	HCE::Logger(HCE::TEST_LEVEL, __PRETTY_FUNCTION__) << "touchType=" << event->type() << std::endl;
    	...
    }
    
    void MyChildQQuickItem::mouseReleaseEvent(QMouseEvent *event){
    	HCE::Logger(HCE::TEST_LEVEL, __PRETTY_FUNCTION__) << "touchType=" << event->type() << std::endl;
    	...
    }
    
    void MyChildQQuickItem::wheelEvent(QWheelEvent *event){
    	HCE::Logger(HCE::TEST_LEVEL, __PRETTY_FUNCTION__) << "touchType=" << event->type() << std::endl;
    	...
    }
    
    void MyChildQQuickItem::touchEvent(QTouchEvent *event){
    	HCE::Logger(HCE::TEST_LEVEL, __PRETTY_FUNCTION__) << "touchType=" << event->type() << std::endl;
    	...
    }
    
    void MyChildQQuickItem::hoverMoveEvent(QHoverEvent *event){
    	HCE::Logger(HCE::TEST_LEVEL, __PRETTY_FUNCTION__) << "touchType=" << event->type() << std::endl;
    	...
    }
    

    As you can see from the following log, I am receiving the TouchBegin event into childMouseEventFilter function, instead of touchEvent one, where I've correctly received TouchUpdate and TouchEnd.

    [TEST     ] 10/06/2019-07:21:06.247906 (7FCE03EB5A40) virtual bool MyRootWindowQML::event(QEvent*): touchType=194
    [WARNING  ] 10/06/2019-07:21:06.248955 (7FCE03EB5A40) virtual bool MyChildQQuickItem::childMouseEventFilter(QQuickItem*, QEvent*): TouchEvent comes from childMouseEventFilter: touchType=194
    [TEST     ] 10/06/2019-07:21:06.258322 (7FCE03EB5A40) virtual bool MyRootWindowQML::event(QEvent*): touchType=195
    [TEST     ] 10/06/2019-07:21:06.260517 (7FCE03EB5A40) virtual void MyChildQQuickItem::touchEvent(QTouchEvent*): touchType=195
    [TEST     ] 10/06/2019-07:21:06.269321 (7FCE03EB5A40) virtual bool MyRootWindowQML::event(QEvent*): touchType=195
    [TEST     ] 10/06/2019-07:21:06.271481 (7FCE03EB5A40) virtual void MyChildQQuickItem::touchEvent(QTouchEvent*): touchType=195
    [TEST     ] 10/06/2019-07:21:06.282024 (7FCE03EB5A40) virtual bool MyRootWindowQML::event(QEvent*): touchType=195
    [TEST     ] 10/06/2019-07:21:06.287264 (7FCE03EB5A40) virtual void MyChildQQuickItem::touchEvent(QTouchEvent*): touchType=195
    [TEST     ] 10/06/2019-07:21:06.298108 (7FCE03EB5A40) virtual bool MyRootWindowQML::event(QEvent*): touchType=195
    [TEST     ] 10/06/2019-07:21:06.303338 (7FCE03EB5A40) virtual void MyChildQQuickItem::touchEvent(QTouchEvent*): touchType=195
    [TEST     ] 10/06/2019-07:21:06.314658 (7FCE03EB5A40) virtual bool MyRootWindowQML::event(QEvent*): touchType=195
    [TEST     ] 10/06/2019-07:21:06.319867 (7FCE03EB5A40) virtual void MyChildQQuickItem::touchEvent(QTouchEvent*): touchType=195
    [TEST     ] 10/06/2019-07:21:06.336220 (7FCE03EB5A40) virtual bool MyRootWindowQML::event(QEvent*): touchType=195
    [TEST     ] 10/06/2019-07:21:06.336295 (7FCE03EB5A40) virtual void MyChildQQuickItem::touchEvent(QTouchEvent*): touchType=195
    [TEST     ] 10/06/2019-07:21:06.348019 (7FCE03EB5A40) virtual bool MyRootWindowQML::event(QEvent*): touchType=196
    [TEST     ] 10/06/2019-07:21:06.348074 (7FCE03EB5A40) virtual void MyChildQQuickItem::touchEvent(QTouchEvent*): touchType=196
    

    By the documentation (https://doc.qt.io/qt-5/qquickitem.html#childMouseEventFilter), the method childMouseEventFilter should handle only mouse events.

    How can I fix it?

    Thank you.

    Andrea

    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