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. [SOLVED] childMouseEventFilter QQuickItem receive mouse events

[SOLVED] childMouseEventFilter QQuickItem receive mouse events

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 1.6k 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.
  • D Offline
    D Offline
    dasRicardo
    wrote on last edited by
    #1

    Hello,

    i have a little problem. I've wrote my own class derived from QQuickItem. To handle mouse events i implement childMouseEventFilter.

    c++
    @
    childMouseEventFilter(QQuickItem * item, QEvent * event) {
    switch (event->type()) {
    case QEvent::MouseButtonPress: {
    qDebug("mouse press");
    break;
    }
    case QEvent::UngrabMouse:
    qDebug("ungrab");
    break;
    case QEvent::MouseButtonRelease: {
    qDebug("mouse release");
    break;
    }
    default:
    break;
    }
    return false;
    }
    @

    qml

    @
    Rectangle {
    anchors.fill: parent
    color: '#ff0000'
    RippleBehavior {
    color: '#ffffff'
    anchors.fill: parent
    Text {
    anchors.fill: parent
    text: "test"
    // MouseArea {
    // anchors.fill: parent
    // onClicked: {
    // console.log("clicked");
    // }
    // }
    }
    }
    }
    @

    So my problem is MouseButtonRelease is never thrown. If i use MouseArea everything is fine but without, directly after the MouseButtonPressed event i get the UngrabMouse event. What can i do, anybody an idea?

    Thx for any reply

    **Sorry for my english :)

    PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT'S SOLVED.**

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dasRicardo
      wrote on last edited by
      #2

      Alright, i've solved my problem. The trick here is to call the ungrab function from the item that trown the ungrab event.

      @
      childMouseEventFilter(QQuickItem * item, QEvent * event) {
      switch (event->type()) {
      case QEvent::MouseButtonPress: {
      QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
      this->_addRipple(mouseEvent->x(), mouseEvent->y());
      break;
      }
      case QEvent::UngrabMouse:
      qDebug("ungrab");
      item->grabMouse(); // this line here did the magic
      break;
      case QEvent::MouseButtonRelease: {
      RippleNode node = static_cast<RippleNode>(this->_node->lastChild());
      node->fadeOut();
      break;
      }
      default:
      break;
      }
      return false;
      }
      @

      **Sorry for my english :)

      PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT&#x27;S SOLVED.**

      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