QML中ListView向上滚动效果
最近在做一个小的音乐播放器,歌词滚动效果在qml中居然可以很容易的实现。
在QML的源码中找到思路的,现在就把这种效果单独做了个demo出来。
利用的是listView的preferredHighlightBegin和preferredHighlightEnd
源文件:
main.qml
import QtQuick 2.9
import QtQuick.Window 2.2Window {visible: truewidth: 240height: 400title: qsTr("Hello World")HightRange {width: 200height: 400anchors.top: parent.topanchors.topMargin: 20anchors.left: parent.leftanchors.leftMargin: 60}
}
PetsModel.qml文件:
import QtQuick 2.0ListModel {ListElement {name: "Polly"type: "Parrot"age: 12size: "Small"}ListElement {name: "Penny"type: "Turtle"age: 4size: "Small"}ListElement {name: "Warren"type: "Rabbit"age: 2size: "Small"}ListElement {name: "Spot"type: "Dog"age: 9size: "Medium"}ListElement {name: "Schrödinger"type: "Cat"age: 2size: "Medium"}ListElement {name: "Joey"type: "Kangaroo"age: 1size: "Medium"}ListElement {name: "Kimba"type: "Bunny"age: 65size: "Large"}ListElement {name: "Rover"type: "Dog"age: 5size: "Large"}ListElement {name: "Tiny"type: "Elephant"age: 15size: "Large"}
}
HightRange.qml文件:
import QtQuick 2.0Rectangle {id: rootproperty int current: 0property bool increasing: trueSequentialAnimation {id: animloops: -1running: trueScriptAction {script: if (increasing) {current++;if (current >= aModel.count -1) {current = aModel.count - 1;increasing = !increasing;}} else {current--;if (current <= 0) {current = 0;increasing = !increasing;}}}PauseAnimation { duration: 500 }}// MouseArea{// id: ma
// z: 1
// anchors.fill: parent
// onClicked: { z = 1 - z; if (anim.running) anim.stop(); else anim.restart();}
// }ListView {id: listanchors.fill: parentmodel: PetsModel {id: aModel}delegate: petDelegatehighlight: Rectangle { color: "yellow" }currentIndex: root.currentpreferredHighlightBegin: 60preferredHighlightEnd: 120highlightRangeMode: ListView.StrictlyEnforceRange}Component {id: petDelegateItem {width: 160height: 60Column {id: columnText { text: 'Name: ' + name }Text { text: 'Type: ' + type }Text { text: 'Age: ' + age }}MouseArea {anchors.fill: parentonClicked: root.current = index}}}
}
在Qt Creator中查找highlightRangeMode
在第二项就可以找到,然后去Qt安装目录中去找qml的源码既可看到官方的demo。
QML中ListView向上滚动效果相关推荐
- vue键盘抬起_vue实现编辑器键盘抬起时内容跟随光标距顶位置向上滚动效果
最近遇到了之前没有碰到过的一个问题:编辑器输入内容时,最好让内容一直保持在可视区域,比如如果区域超出的话,就在键盘抬起时向上滚动一定距离. 这个和聊天发消息还有一定的区别,聊天的话是只要点开输入框,就 ...
- 原生js实现文字无缝向上滚动效果
在网上查找到了一个实现文字无缝向上滚动效果的源码,结果发现运行有问题,于是就稍加改动,实现了js无缝向上滚动的效果. <script>window.onload = roll(50); f ...
- 简单的jQuery无缝向上滚动效果
简介 这是一个基于 jQuery 的简单的向上滚动效果插件,代码很少,功能也比较单一,可用于文字或图片滚动,鼠标移动到上面会暂停滚动.功能虽然单一,不过一般情况下也够用了,而且还很小巧. 兼容 兼容所 ...
- 原生js实现文字循环向上滚动效果
原生js实现文字循环向上滚动效果 css样式 (最外层的div的高度不要太高,也不要正好包含内容区域的高度,最好比内容区域高度低点,产生滚动条) #scrollArea {width: 400px; ...
- QML中ListView的深度订制,并利用其实现自定义ComboBox和TreeView
1.ListView的滚动条样式订制 2.基于(1.ListView的滚动条样式订制)实现一个简单的代理自定义ComboBox 3.基于(1.ListView的滚动条样式订制)实现一个复杂的代理Tre ...
- jQuery无缝向上滚动效果
该篇通过js和jquery两种写法来实现内容无缝向上滚动的一个效果,废话不多说,直接上代码 (1)向上滚动 HTML: <div id="demo" style=" ...
- html table表格无缝向上滚动效果,js实现表格无缝滚动效果
table表格无缝向上滚动 height: 500px; overflow: hidden; position: relative; width: 1000px; margin: 100px auto ...
- 关于文字向上滚动效果
1.文字无缝向上滚动 <div class="tui-new-apply clearfix"><span>[最新资讯]</span><ul ...
- js实现向上滚动效果
源码: <style type="text/css"> #up_zzjs{border:1px solid #ccc;width:170px;height:182px; ...
最新文章
- android监听器在哪里创建,[转载]android开发中创建按钮事件监听器的几种方法
- 华为12月份鸿蒙适配mate40,华为:Mate40系列在12月可优先升级鸿蒙系统
- [Material Design] 教你做一个Material风格、动画的button(MaterialButton)
- 主要矛盾和次要矛盾_次要GC,主要GC与完整GC
- java 进度条jsp,jsp进度条_jsp技巧
- docker集群管理工具_太多选择:如何选择正确的工具来管理Docker集群
- git push 报错:you are not allowed to upload merges
- 如何在Java项目中查找未使用/无效的代码
- sqoop和sqoop2区别
- 大学excel题库含答案_2017excel试题库附答案.doc
- 【python】pycharts画关联图
- 一次泛微OA宕机事件的解决。
- ODC预端接光纤配线箱
- 【hadoop】汽车销售数据统计分析项目(部分)
- 来自灵魂的拷问——知道什么是SQL执行计划吗?
- HTML5+CSS期末大作业:环保网站设计——环境保护(10页) 含设计报告 HTML+CSS+JavaScript 静态HTML环境保护网页制作下载 DIV+CSS环保网页设计代码
- 用html编写诗句春晓,唐诗与灯谜1:《春晓》
- google语音服务注意事项
- 入门web开发第一个项目1.0版本
- 一、Mavlink协议