// Copyright (C) 2026 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
    \page qtquick-states-when-conditions.html
    \previouspage creator-how-tos.html

    \ingroup creator-how-to-design-qtquick-states

    \title Set when conditions

    Set \c when conditions to evaluate the truthfulness of several components'
    properties and move the UI to the state in which these conditions apply.
    You can evaluate whether something is true or false, greater than or equal
    to something else, and so on. You can also use operators, such as AND or
    OR, to evaluate the truthfulness of several components.

    To determine when a state is applied:

    \list 1
        \li Go to \uicontrol {View} > \uicontrol {Views} > \uicontrol {States}.
            \image {qmldesigner-transitions.png} {States view.}
        \li In \uicontrol {When Condition}, select \imageedit.
        \li In \uicontrol {Binding Editor}, specify a \l [QtQuick]{State::when}
            {when} property for the state.
        \li Set the value of the property to a boolean expression that evaluates
            to \c true when you want to apply the state.
    \endlist

    The \c when conditions are evaluated from left to right and in order of
    appearance in the code. Therefore, if you have two conditions for two
    different states that both evaluate to \c true, the first state is applied.

    \section1 Create conditional bindings

    In \uicontrol {Binding Editor}, select the component and property to
    create the expression. For example, to change the state when a button is
    pressed, you could select a button component and its pressed property.

    \image {qtquick-states-binding-editor.png} {Binding Editor in States view.}

    When you compose the expressions in \uicontrol {Binding Editor}, the
    \l{Complete code}{code completion} feature lists the components and
    their properties you can use in the expressions.

    \include creator-logical-operators.qdocinc logical operators

    \section1 Examples of when conditions

    To apply a state to a button when the button is pressed, write:

    \code [text]
    when: control.pressed
    \endcode

    To apply a state when the button is not pressed, select \uicontrol NOT.

    \image {qtquick-states-binding-editor-not.png} {NOT checkbox in Binding Editor.}

    To apply a state when the button is not pressed, selected, nor hovered on,
    combine conditions, as follows:

    \code [text]
    when: !control.pressed && !control.checked && !control.hovered
    \endcode

    To apply a state when the button is pressed or selected, but not hovered on,
    write:

    \code [text]
    when: control.pressed || control.checked && !control.hovered
    \endcode

    \sa {Work with states}{How to: Work with states}, {Qt Quick UI design},
    {Designing Qt Quick UIs}
*/
