The Symbian-specific ListItem component has inbuilt support for handling 'up' and 'down' hardware keys. When the ListView has focus, the 'up' key will decrement the current index. Similarly, the 'down' key will increment the current index.
Focus can be set to the ListView using Item::ForceActiveFocus() method. For example:
ListView { id: listView Component.onCompleted: { listView.forceActiveFocus() }
If you want to use other hardware keys, the Keys property in the ListItem provides a mechanism for doing so. You can handle hardware key presses with the Keys.onPressed() and Keys.onReleased() handlers.
Here is an example of a ListView delegate which deletes a list item when the user presses the backspace key.
Component { id: listDelegate ListItem { id: listItem Keys.onPressed: { if (event.key == Qt.Key_Backspace) { if (listView.currentIndex >= 0) listView.model.remove(listView.currentIndex) } } } }
Sometimes it is necessary to select a control inside the ListItem. It is possible to extend ListItem component to handle 'left' key and 'right' key to select a control.
Component { id: listDelegate ListItem { id: listItem Row { width: parent.width anchors.fill: parent.paddingItem ListItemText { mode: listItem.mode role: "Title" text: name // Title text is from the 'name' property in the model item (ListElement) width: parent.width - (button1.width + button2.width) } Button { id : button1 text: "Reply" checked: activeFocus } Button { id : button2 text: "Delete" checked: activeFocus onClicked: listView.model.remove(listView.currentIndex) } } KeyNavigation.right: button2 KeyNavigation.left: button1 } }