![]() |
Home · All Classes · All Functions · Overviews |
Files:
The Maemo 5 List Pick Selector example shows how to create a Maemo 5 "Picker Button". A "Picker Button" is a button that displays a label and lets the user pick a value from a list when pressed. The chosen value can be displayed either below or next to the button's main text.
In order to create a Maemo 5 "Picker Button" with Qt, a model needs to be created and populated. In this example, a QStandardItemModel with one column is used:
QStandardItemModel model(0, 1); populateListModel(&model);
The function populateListModel() populates the model with some example values.
The widget QMaemo5ValueButton encapsulates the Maemo 5 "Picker Button". The class QMaemo5ListPickSelector encapsulates choosing a value from a list.
QMaemo5ValueButton *button1 = new QMaemo5ValueButton("Value besides text");
button1->setValueLayout(QMaemo5ValueButton::ValueBesideText);
QMaemo5ListPickSelector *selector1 = new QMaemo5ListPickSelector;
selector1->setModel(&model);
// not setting the current index means that the value is empty.
button1->setPickSelector(selector1);
First, a QMaemo5ValueButton is created. The text "Value besides text" is the button's main text.
QMaemo5ValueButton::setValueLayout() decides where the chosen value is shown in relation to the button's main text. In this example, we choose to show the value next to the button's main text.
The QMaemo5ListPickSelector is created, and the example model is set. Finally, the QMaemo5ListPickSelector is set as the button's selector. Note that the button takes ownership of the selector. The selector is deleted when the button is deleted.
For the next button, a more complex model is created:
QStandardItemModel tableModel(0, 0); populateTableModel(&tableModel);
The populateTableModel() function populates the model with example values spanning three columns.
Using this model is not much different from the last example button:
QMaemo5ValueButton *button2 = new QMaemo5ValueButton("Value under text"); button2->setValueLayout(QMaemo5ValueButton::ValueUnderText); QMaemo5ListPickSelector *selector2 = new QMaemo5ListPickSelector; selector2->setModel(&tableModel); selector2->setModelColumn(2); selector2->setCurrentIndex(5); button2->setPickSelector(selector2);
Again, a button is created, but this time the chosen value appears under the button's main text. Note that only one column of the demo table model can be displayed as the value of the button. In this example, QMaemo5ListPickSelector::setModelColumn() is used to set the third column of the model to be displayed as the button's value.
Finally, the first row of the model is set as the preset value of the button.
Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies) | Trademarks | Qt 4.6.2 |