我已经创建了一个带有滚动条的ListView。像这样: 以下是我的代码:ListView { id: listView; ScrollBar.vertical: ScrollBar { id: bar //x :100 doesn't work active: true } } 在我的情况下,我想重置滚动条的位置。例如,将滚动条向右移动5像素。我尝试了设置"x:",但没有起作用。我该如何解决这个问题。
您可以将ScrollBar移动到ListView之外,并使用其id在ListView内引用它:ListView { id: listView ScrollBar.vertical: bar } ScrollBar { id: bar active: true anchors { left: listView.left top: listView.top bottom: listView.bottom leftMargin: 100 } }
在加载ScrollBar后的一瞬间,您需要设置该属性,因为ListView会将其设置为默认位置。 ScrollBar.vertical: ScrollBar { id: sb active: true Component.onCompleted: x = 100 }