MeeGo 1.2 Harmattan Developer Documentation Develop for the Nokia N9

QML SelectionDialog Element

Single selection dialog. More...

Inherits Item

This element was introduced in qt-components 4.7.

Properties

Detailed Description

The SelectionDialog is a dialog that allows the user to select a single item from several list elements.

 // Create a selection dialog with a title and list elements to choose from.
 SelectionDialog {
     id: singleSelectionDialog
     titleText: "Dialog Header #1"
     selectedIndex: 1

     model: ListModel {
         ListElement { name: "ListTitle #1" }
         ListElement { name: "ListTitle #2" }
         ListElement { name: "ListTitle #3" }
     }
 }

As with all dialogs the visual parent property is used to specify which area of the screen is grayed out while the menu is opened. If no visual parent is set then it is determined automatically and falls back to the root item.

The dialog is opened via the open() call:

 Button {
     text: "SingleSelection"
     onClicked: {
         singleSelectionDialog.open();
     }
 }

The dialog is automatically accepted and closed once an item got selected by the user. The name of the selected ListElement from the model is queried through the selectedIndex property:

 Text {
     anchors.centerIn: parent
     text: singleSelectionDialog.model.get(singleSelectionDialog.selectedIndex).name
 }

In order to allow the user to pick several items from a list a MultiSelectionDialog is used.

Common API

 property ListModel model
 property int selectedIndex

 property Component delegate
 // Style API
 property Style platformStyle

See also Dialog and MultiSelectionDialog.

Property Documentation

delegate : Component

The delegate that is used in order to render the ListElements inside the ListView of the SelectionDialog. The SelectionDialog provides a default delegate that renders the ListElements according to the UI guidelines. The default delegate can be exchanged by a custom one.


model : ListModel

The ListModel used for the contents of the dialog. The default is an empty list model. The names of the ListElements stored inside the model are displayed as items the user can choose from.


platformStyle : Style

Property default is SelectionDialogStyle{}

Property for styling the component.


selectedIndex : int

Returns the index of the ListElement selected by the user from the SelectionDialog. Property default is -1 (no selection). If the property is set during the declaration of the dialog then the preselected item is highlighted in order to suggest the default choice.