qt帮助文档,以及网上,以及AI目前都没有这个知识点的介绍,通过九牛二虎之力摸索出来的方法,ScrollBar.horizontal.onPositionChanged事件监听,children[2]获取到水平滚动条,进而获取到position,直接用position会报错。下面是具体代码:
ScrollView {id: dataDetailsScrollViewanchors.fill: parentclip: truecontentWidth: 4000wheelEnabled: trueRectangle {width: dataDetailsScrollView.contentWidthheight: 10color: "red"}ScrollBar.horizontal.wheelEnabled: trueScrollBar.horizontal.policy: ScrollBar.AlwaysOnScrollBar.horizontal.onPositionChanged: {var children = dataDetailsScrollView.childrenvar barHorizontal = children[2]console.log(barHorizontal.position)}}