Slint Kit Documentation

Numbers and money

KitPercentField

Decimal field presenting a percentage with its symbol.

Decimal field presenting a percentage with its symbol.
Native screenshot of the same example, rendered with Skia.

Bind text to a percentage controller and make the domain convention explicit, such as 25 for 25%. Handle validation through inherited callbacks.

The default suffix is %. The component does not divide the value by one hundred or alter its precision.

Complete example

This complete Slint file is a visual composition used to produce the screenshot above. Internal strings without a label property retain the kit’s default language; system dialogs follow the host platform. Projected state and callbacks requesting a decision need host wiring; the standalone fixture does not supply that controller. Set up the Rust project, then see the typed controller application for working editing, validation and selection.

// SPDX-License-Identifier: GPL-3.0-or-later
// Display projections are fixtures. Validate accepted domain values in Rust.
import { KitPercentField, KitTheme, KitThemes } from "@kit/kit.slint";

export component Example inherits Window {
    title: "KitPercentField example";
    preferred-width: 420px;
    preferred-height: 180px;
    max-width: 100000px;
    max-height: 100000px;
    background: root.theme.canvas;
    in-out property <KitTheme> theme: KitThemes.light;
    in-out property <string> status;
    VerticalLayout {
        padding: 24px; spacing: 16px; alignment: start;
        Text { text: "Percent Field"; color: root.theme.text-primary; font-size: 20px * root.theme.text-scale; font-weight: 600; }
        KitPercentField { theme: root.theme; label: "Tax rate"; text: "8.25"; edited(value) => { root.status = "Draft: " + value; } }
        if root.status != "": Text { text: root.status; color: root.theme.text-secondary; font-size: 12px * root.theme.text-scale; wrap: word-wrap; }
    }
}

Download this example

Public API

Inherits KitDecimalField. The declarations below come from the component source. Parent properties remain available; see the controller guide for state management.

See also