我有一个两列布局,左列中有一个 ListView。使用左/右键,我可以在应用程序的两个部分之间更改焦点。
左列的活动焦点被委托给 ListView 并从那里直接到它的行之一。
如何检查 ListView 或其中一个孩子是否有焦点?
import QtQuick 1.1
FocusScope {
width: 960
height: 540
id: app
focus: true
FocusScope {
id: leftColumn
KeyNavigation.right: rightColumn
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.top: parent.top
width: 250
focus: true
Rectangle {
id: leftBackgroundColor
anchors.fill: parent
color: contactsList.activeFocus ? "red" : "#E6E6E6"
ListView {
id: contactsList
interactive: true
anchors.fill: parent
focus: true
delegate: Text {
text: name
font.bold: activeFocus
}
model: ListModel {
ListElement { name: "Simon" }
ListElement { name: "Mary" }
ListElement { name: "Jack" }
ListElement { name: "Frank" }
}
}
}
}
FocusScope {
id: rightColumn
KeyNavigation.left: leftColumn
anchors.left: leftColumn.right
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.top: parent.top
onFocusChanged: console.log("Right focus changed: " + focus + "/" + activeFocus)
Rectangle {
id: rightBackgroundColor
anchors.fill: parent
focus: true
color: activeFocus ? "red" : "#b3b3b3"
}
}
}