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. QQuickItem can't catch MouseButtonRelease in C++
Forum Updated to NodeBB v4.3 + New Features

QQuickItem can't catch MouseButtonRelease in C++

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 1.3k 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.
  • A Offline
    A Offline
    archqt
    wrote on last edited by A Former User
    #1

    Hi,
    i did a few program to show you the program. I try to catch PressEvent and ReleaseEvent but it doesn't work with simple Click. It only work on DoubleClick but all buttons except the Left One (sic)

    Here is the QML test

    import QtQuick 2.5
    import QtQuick.Window 2.0
    import QtQuick.Controls 1.4
    import GestureArea 1.0
    
    
    ApplicationWindow {
        visible: true
        
        GestureArea {
            anchors.fill: parent
            z: 1000
            opacity: 0.2
            focus: true
            onClicked: console.log('Click');
            onReleased: console.log('Released')
      /*      
            MouseArea {
                anchors.fill: parent
                propagateComposedEvents: true
                onPressed: console.log('GestureArea Click');
                onReleased:console.log('gestureArea Released');
            }
       */     
            
        }
    }
    

    Here is the GestureArea.h file

    #ifndef GESTUREAREA_H
    #define GESTUREAREA_H
    
    #include <QtQuick>
    
    class GestureArea : public QQuickItem
    {
        Q_OBJECT
    public:
        GestureArea();
        void PressEvent(QMouseEvent *event);
        void ReleaseEvent(QMouseEvent *event);
        bool event(QEvent *e);
    signals:
        void clicked(QMouseEvent *event);
        void released(QMouseEvent *event);
    };
    
    #endif // GESTUREAREA_H
    
    

    And the cpp file GestureArea.cpp

    #include "gesturearea.h"
    #include <QtQuick>
    #include <QDebug>
    
    GestureArea::GestureArea()
    {
        qDebug()<<"GestureArea::GestureArea()";
        setAcceptHoverEvents(true);
        setAcceptedMouseButtons(Qt::AllButtons);
        setFlag(ItemAcceptsInputMethod, true);
        setFlag(QQuickItem::ItemHasContents);
    }
    
    bool GestureArea::event(QEvent *e)
    {
        qDebug()<<(int)e->type();
        if (e->type()==QEvent::MouseButtonRelease) ReleaseEvent((QMouseEvent*)e);
        if (e->type()==QEvent::MouseButtonPress) PressEvent((QMouseEvent*)e);
        QQuickItem::event(e);
        return true;
    }
    
    void GestureArea::PressEvent(QMouseEvent *event)
    {
        qDebug()<<"void GestureArea::PressEvent(QMouseEvent *event)";
        emit clicked(event);
    }
    
    void GestureArea::ReleaseEvent(QMouseEvent *event)
    {
        qDebug()<<"void GestureArea::ReleaseEvent(QMouseEvent *event)";
        emit released(event);
    }
    

    I decided to overload event function to see the type of event i could catch.
    On the QML file when i put a MouseArea it can catch Press/Relesease

    But my goal is to catch these events on the C++ code.

    Sincerely

    1 Reply Last reply
    0
    • jpnurmiJ Offline
      jpnurmiJ Offline
      jpnurmi
      wrote on last edited by
      #2

      In order to receive a mouse release event, an item must accept the preceding press event.

      A 1 Reply Last reply
      0
      • jpnurmiJ jpnurmi

        In order to receive a mouse release event, an item must accept the preceding press event.

        A Offline
        A Offline
        archqt
        wrote on last edited by
        #3

        @jpnurmi said:

        In order to receive a mouse release event, an item must accept the preceding press event.

        Ok thanks, but in this case there is a problem because what i want to do with this code is to be able to catch all events below this Item.
        Why do i want this ? to make a Gesture Capture because i don't think this exist on Qt. I want to have the "force" of the movement....But it doesn't exist on QtQuick.
        What i want is a Component in C++ that is above all others and can catch all events. A bit like a filterEvent but without knowing what is above my GestureArea

        Sincerely

        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