У меня есть ListView
, включая много переключателей. Список больше видимой области. Один из переключателей отмечен. Иногда, если кнопка выбрана радио находится за пределами видимой области, я хочу, чтобы перейти к нему:Как вертикальная прокрутка к определенному товару
ScrollView {
anchors.fill:parent
ListView {
anchors.fill: parent
model: valuesList
delegate: RadioButton {
id: radioBtn
//check of value is index type and do the corresponding checked? test
checked: valueIsIndex ? (parseInt(valueFromParent) == index ? true : false) : (valueFromParent == valueString ? true : false)
onClicked: {
root.selected(valueString, index)
}
Component.onCompleted: {
if(checked)
//Here i want to scroll the list to display this radiobutton
}
}
}
}
Любые идеи, Howto, чтобы получить список прокручивается? Я много играл с hightlights
и contentY
, но ничего не получилось.
Я использую ScrollView
вокруг ListView
, чтобы автоматически получать полосы прокрутки на рабочем столе. На мобильных устройствах у меня есть только потрясающий ListView
.
EDIT
я получить его на пути с помощью BaCaRoZzo. Вот мой текущий рабочий пример:
ScrollView {
id: scrollView
anchors.fill:parent
property int yOfCheckedRadioButton: 0
ListView {
id:listView
anchors.fill: parent
spacing: Math.round(appWindow.height*0.05)
model: internalValuesList
delegate: RadioButton {
id: radioBtn
//check of value is index type and do the corresponding checked? test
checked: checktest()
style: MyRadioButtonStyle {
myRadioBtn: radioBtn
labelString: value
}
Component.onCompleted: {
//set the position of the checked RadioButton to scroll to it later onContentHeightChange
if(checked) {
var checkedRadioBtnPositionY = Math.round((radioBtn.height + listView.spacing) * index - radioBtn.height * 1.5)
if(checkedRadioBtnPositionY > 0)
scrollView.yOfCheckedRadioButton = checkedRadioBtnPositionY
else
scrollView.yOfCheckedRadioButton = 0
}
}
}
onContentHeightChanged: {
//scroll to the checked RadioButton
contentY = scrollView.yOfCheckedRadioButton
}
}
}
'ContentY' должно работать (как показано, например, [этот ответ] (http://stackoverflow.com/a/30378458/2538363)). Вы должны обязательно учитывать присутствие «ListView» здесь. – BaCaRoZzo
В качестве основного теста я попытался следовать в конце 'ListView': ' Component.onCompleted: { contentY = 200 } ' Но это тоже ничего не меняет. Что я делаю неправильно? – fhammer
Не нравится. [Это] (http://pastebin.com/embed_js.php?i=EwT9nfRH) работает – BaCaRoZzo