Responding to user actions events in QML code is done by adding scripts to slots of the items, in quite a similar way to Qt Widgets. The difference here is that each signal defined internally within a QML type also has a corresponding slot for it which is automatically generated and can be filled with a script to perform an action when the relevant signal is emitted. Well, let's see this with another example. A QML Button
type has a pressed signal. This automatically means that there is an onPressed
slot that you can use to code the required action of the specific button. Here's an example code:
Button { onPressed: { // code goes here } }
For a list of available slots in QML types, you can refer to the Qt documentation. As mentioned before, you can easily guess the slot name of each signal by capitalizing the first letter of the signal name and prepending on
to it. Thus, for the pressed
signal you'll have...