我正在为UI构建基于Qt-Quick 2的Qt5应用程序。显示带有突出显示组件的ListView时出现问题。当我滚动ListView时,突出显示的矩形在ListView之外可见,我找不到避免它的方法。
这是一个带有最小QML文件的问题的示例:
import QtQuick 2.0
Rectangle {
width: 360; height: 600
ListView {
width: 350; height: 200
anchors.centerIn: parent
id: myList
model: myModel
highlight: highlightBar
delegate: Item {
width: 400; height: 20
Text { text: name }
MouseArea {
id: mArea
anchors.fill: parent
onClicked: { myList.currentIndex = index; }
}
}
}
Component {
id: highlightBar
Rectangle {
width: parent.width; height: 20
color: "#FFFF88"
}
}
ListModel {
id: myModel
}
/* Fill the model with default values on …Run Code Online (Sandbox Code Playgroud)