Nominate our 2022 Qt Champions!

How to make a QQuickItem which will route mouse events to other QuickItem?

  • I do not understand the right approach of QMouseEvent and QTouchEvent forwarding? Because there are PressEvent, MoveEvent and ReleaseEvent types which is not clear how to use when forwarding.
    Should I create a new QMouseEvents or ignore() existing to make them propagate? Or What is right approach?

    Uss case
    Goal is to accept mouse events in MapListEventsRouter which is inherited from QQuickItem and forward it to Map or List.
    MapListEventsRouter also controls height of Map and List. Idea is that when scrolling List down, first Map height is decreasing to 0, next the events should go directly to List.
    I have reimplemented

    void mousePressEvent(QMouseEvent* event) override;
    void mouseReleaseEvent(QMouseEvent* event) override;
    void mouseMoveEvent(QMouseEvent* event) override;

    to achieve desired logic, but MouseEvents do not go to Map or List. I have tried event->ignore(), QCoreApplication::sendEvent(_list, event) but with no success. Events just do not propagate to Map or List.
    What do I do wrong?

    // simplified code
    Item {
        id: root
    Map {
        id: aMap
        height: mapListRouter.mapHeight
       width: parent.width
    ListView {
        id: aList
        height: mapListRouter.listHeight
        width: parent.width
    MapListEventsRouter {
                    id: mapListRouter
                    height: parent.height
                    width: parent.width
                    map: aMap
                    list: aList

Log in to reply