Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

pi/agent/skills/optional/qml/references/signals.md

Raw
Rendered preview

Signals and input

Signals communicate events and user intent without exposing component internals. Property change signals communicate state changes, not necessarily user actions.

Item {
    id: root
    signal activated(string source)

    TapHandler {
        onTapped: root.activated("pointer")
    }
}

Use a handler on the emitting object when it owns the response. Use Connections when another object or a replaceable target owns the response.

Connections {
    target: backend
    function onStatusChanged() {
        statusLabel.text = backend.status
    }
}

User intent versus property changes

Choose user-only Control signals when writing state back to its owner:

Slider {
    value: settings.volume
    onMoved: settings.volume = value
}

onValueChanged also runs when the value changes programmatically and can create feedback writes. The assignment to settings.volume does not break the binding on Slider.value. An imperative assignment to Slider.value would replace that binding.

Keyboard and focus

A Keys handler receives events only while its item has active focus. Use Controls for standard keyboard behavior, Shortcut for shortcuts, and custom key handlers only for component-specific behavior. Verify focus entry, traversal, activation, and exit rather than assuming pointer behavior covers keyboard interaction.

Custom interactive items must expose an appropriate Accessible.role, a meaningful Accessible.name, keyboard activation, and a visible focus state.

# Signals and input

Signals communicate events and user intent without exposing component internals.
Property change signals communicate state changes, not necessarily user actions.

```qml
Item {
    id: root
    signal activated(string source)

    TapHandler {
        onTapped: root.activated("pointer")
    }
}
```

Use a handler on the emitting object when it owns the response.
Use `Connections` when another object or a replaceable target owns the response.

```qml
Connections {
    target: backend
    function onStatusChanged() {
        statusLabel.text = backend.status
    }
}
```

## User intent versus property changes

Choose user-only Control signals when writing state back to its owner:

```qml
Slider {
    value: settings.volume
    onMoved: settings.volume = value
}
```

`onValueChanged` also runs when the value changes programmatically and can create feedback writes.
The assignment to `settings.volume` does not break the binding on `Slider.value`.
An imperative assignment to `Slider.value` would replace that binding.

## Keyboard and focus

A `Keys` handler receives events only while its item has active focus.
Use Controls for standard keyboard behavior, `Shortcut` for shortcuts, and custom key handlers only for component-specific behavior.
Verify focus entry, traversal, activation, and exit rather than assuming pointer behavior covers keyboard interaction.

Custom interactive items must expose an appropriate `Accessible.role`, a meaningful `Accessible.name`, keyboard activation, and a visible focus state.