IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

ExclusiveGroup QML Type

ExclusiveGroup provides a way to declare several checkable controls as mutually exclusive.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

ExclusiveGroup QML Type

  • Import Statement: import QtQuick.Controls 1.4

  • Group: ExclusiveGroup is part of Buttons and Controls

Detailed Description

ExclusiveGroup can contain several Action items, and those will automatically get their Action::exclusiveGroup property assigned.

 
Sélectionnez
ExclusiveGroup {
    id: radioInputGroup

    Action {
        id: dabRadioInput
        text: "DAB"
        checkable: true
    }

    Action {
        id: fmRadioInput
        text: "FM"
        checkable: true
    }

    Action {
        id: amRadioInput
        text: "AM"
        checkable: true
    }
}

Several controls already support ExclusiveGroup, e.g. Action, MenuItem, Button, and RadioButton.

As ExclusiveGroup only supports Action as child items, we need to manually assign the exclusiveGroup property for other objects.

 
Sélectionnez
GroupBox {
    id: group2
    title: qsTr("Tab Position")
    Layout.fillWidth: true
    RowLayout {
        ExclusiveGroup { id: tabPositionGroup }
        RadioButton {
            id: topButton
            text: qsTr("Top")
            checked: true
            exclusiveGroup: tabPositionGroup
            Layout.minimumWidth: 100
        }
        RadioButton {
            id: bottomButton
            text: qsTr("Bottom")
            exclusiveGroup: tabPositionGroup
            Layout.minimumWidth: 100
        }
    }
}

Adding support to ExclusiveGroup

It is possible to add support for ExclusiveGroup for an object or control. It should have a checked property, and either a checkedChanged, toggled(), or toggled(bool) signal. It also needs to be bound with ExclusiveGroup::bindCheckable() when its ExclusiveGroup typed property is set.

 
Sélectionnez
Item {
    id: myItem

    property bool checked: false
    property ExclusiveGroup exclusiveGroup: null

    onExclusiveGroupChanged: {
        if (exclusiveGroup)
            exclusiveGroup.bindCheckable(myItem)
    }
}

The example above shows the minimum code necessary to add ExclusiveGroup support to any item.

Property Documentation

 

current : object

The currently selected object. Defaults to the first checked object bound to the ExclusiveGroup. If there is none, then it defaults to null.

Method Documentation

 

void bindCheckable(object)

Register object to the exclusive group.

You should only need to call this function when creating a component you want to be compatible with ExclusiveGroup.

See Also

void unbindCheckable(object)

Unregister object from the exclusive group.

You should only need to call this function when creating a component you want to be compatible with ExclusiveGroup.

See Also

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+