最近在做一个小的音乐播放器,歌词滚动效果在qml中居然可以很容易的实现。
在QML的源码中找到思路的,现在就把这种效果单独做了个demo出来。
利用的是listView的preferredHighlightBegin和preferredHighlightEnd
源文件:
main.qml
import QtQuick 2.9
import QtQuick.Window 2.2
Window {
visible: true
width: 240
height: 400
title: qsTr("Hello World")
HightRange {
width: 200
height: 400
anchors.top: parent.top
anchors.topMargin: 20
anchors.left: parent.left
anchors.leftMargin: 60
}
}
PetsModel.qml文件:
import QtQuick 2.0
ListModel {
ListElement {
name: "Polly"
type: "Parrot"
age: 12
size: "Small"
}
ListElement {
name: