Skip events between QML objects

I have a situation where I would like to pass a QML event to another QML element in the middle of the initial event handler. eg.

Item {
   id: item1

   Keys.onPressed: {
      // Pre-process...

      passEventToObject(event, item2);

      // Post-process based on results of event passing...
   }
}

TextInput {
   id: item2
   // Expect key press event to be handled by text input
}

What can I do to achieve passEventToObject?

Notes:

  • I don’t have access to change Keys.onPressedinside item2, it is built into QML ( TextInput).
  • The event should take place in the middle item1.Keys.onPressed
0
source share
3 answers

++ QCoreApplication::sendEvent. , Qt QML KeyEvent ++ QKeyEvent, :

bool EventRelay::relayKeyPressEvent(
   int key,
   Qt::KeyboardModifiers modifiers,
   const QString& text,
   bool autoRepeat,
   ushort count) const
{
   QKeyEvent event(QKeyEvent::KeyPress, key, modifiers, text, autoRepeat, count);
   return relayEventToObject(&event, mpTargetObject);
}

:

EventRelay { id: relay }

Item {
   id: item1
   Keys.onPressed: {
      // Pre-process...

      relay.relayEventToObject(event, item2);

      // Post-process...
   }
}

TextInput {
   id: item2
}
+2

, "Signal to Signal Connect", . , connect, .

forword ( ), forwardTo:

, , . , , (, ) (, ). , , , , .

.

0

:

Item {
   id: item1
   Keys.onPressed: {
      // Pre-process...
      item2.Keys.pressed(event);
      // Post-process based on results of event passing...
   }
}

Item {
   id: item2
   Keys.onPressed: {
      // Some other stuff happens here
   }
}
0

Source: https://habr.com/ru/post/1537986/


All Articles