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. How to inject synthetised events in Qt5 SceneGraph

How to inject synthetised events in Qt5 SceneGraph

Scheduled Pinned Locked Moved QML and Qt Quick
qtquick sendeve
1 Posts 1 Posters 754 Views 2 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.
  • S Offline
    S Offline
    sraboisson
    wrote on last edited by
    #1

    Hello all,

    I'm in Qt5.3.2.
    I need to synthetise and inject interaction events (Mouse events, keyboard events, touch events), into a QML Scene (Qt5 scenegraph).
    I have a pluggin that correctly receive interaction commands from network, but I can't manage to re-inject those events into the scene graph.
    Here is my code for synthetising and injecting events into the scenegraph :

    void InteractionInjector::injectMouseEvent(/*BlaBlaBla...*/)
    {
        QQuickWindow *lWindow = (QQuickWindow *)QGuiApplication::allWindows().first();
        QQuickItem* lRootItem = lWindow->contentItem();
        
        ...
        
        /*  Recursively send event to all objects in the scenegraph) */
        recurseInjectMouseEvent(lWindow, lRootItem, m_mouseScenePos,
                                (m_mouseButtonState == Pressed)?  QEvent::GraphicsSceneMousePress : 
                                                                  QEvent::GraphicsSceneMouseRelease);
    }
    
    void InteractionInjector::recurseInjectMouseEvent(QQuickWindow *pWindow, QQuickItem *pRootItem, QPoint pScenePos, QEvent::Type pEvent)
    {
        QGraphicsSceneMouseEvent* lEvent;
        bool lResult = false;
        
        lEvent = new QGraphicsSceneMouseEvent(pEvent);
        lEvent->setScenePos(pScenePos);
        lEvent->setButton  (Qt::LeftButton);
        lEvent->setButtons (Qt::LeftButton);
        lEvent->setAccepted(true);
        lResult = pWindow->sendEvent(pRootItem, lEvent);        /*  I always get lResult = false  (why ?)   */
        QApplication::postEvent((QObject*)pRootItem, lEvent);   /*  I also tryed this ....              */
    
        /*  Recursively iterate through scenegraph hyerarchy  */
        foreach(QQuickItem* lChild, pRootItem->childItems())
        {
            stc_recurseSend(pWindow, lChild, pScenePos, pEvent);
        }
    }
    

    In the QML file:

    ...
    
        MouseArea {
            anchors.fill: parent
            onPressed:  console.log("MouseArea::onPressed");
            onReleased: console.log("MouseArea::onReleased");
            onClicked:  console.log("MouseArea::onClicked");
        }
    

    I can't manage to get my QML MouseArea's onPressed, onReleased, or onClicked called from my pluggin.
    As I mentioned as a comment in the code, I alwas get lResult=false, for all widgets in the scenegraph, but I don't know why ?
    Am I doing something wrong ?
    Do I really have to parse all the objects in the scenegraph to inject an event, or is there a kind of
    "lWindow->getSceneGraph()->sendEvent(...)" somewhere ?

    Note: The same kind of code was working in Qt4, but with Qt5 ScenGraph I can't manage to get this functionnality to work again.

    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