• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Kevin Cheng's Yard
电脑是我的老婆,编程是我的灵魂,代码是我的语言,按键是我在歌唱。
https://github.com/surfsky/
博客园    首页    新随笔    联系   管理    订阅  订阅

qt qml scrollbar 移动APP风格的滚动轴

依附于Flickable组件的滚动轴
    自动放置在恰当位置
    拖动时显示,不动时消失
Lisence: MIT 请保留此声明
Author: surfsky.cnblogs.com 2014-12

【先看效果】

【下载】

http://download.csdn.net/detail/surfsky/8426563

【核心代码】

 1 ScrollBar {
 2     id: root
 3     opacity: 0
 4     orientation: Qt.Vertical
 5 
 6     // 绑定到Flickable组件
 7     property Flickable target : Flickable{}
 8 
 9     // 位置
10     width: orientation==Qt.Vertical ? 10 : target.width-10
11     height: orientation==Qt.Vertical ? target.height-10 : 10
12     anchors.right: orientation==Qt.Vertical ? target.right : undefined
13     anchors.bottom: orientation==Qt.Vertical ? undefined : target.bottom
14 
15     // 滚动
16     position: orientation==Qt.Vertical ? target.visibleArea.yPosition   : target.visibleArea.xPosition
17     pageSize: orientation==Qt.Vertical ? target.visibleArea.heightRatio : target.visibleArea.widthRatio
18 
19 
20     // 移动时显隐滚动轴
21     Connections{
22         target: root.target
23         onMovingVerticallyChanged: {
24             if (target.movingVertically)
25                 fadeIn.start();
26             else
27                 fadeOut.start();
28         }
29         onMovingHorizontallyChanged: {
30             if (target.movingHorizontally)
31                 fadeIn.start();
32             else
33                 fadeOut.start();
34         }
35     }
36     NumberAnimation { id:fadeIn;  target: root; properties: "opacity"; duration: 400; from:0; to:1 }
37     NumberAnimation { id:fadeOut; target: root; properties: "opacity"; duration: 400; from:1; to:0 }
38 }

 

【调用示例】

1     FlickableScrollBar {
2         target: view
3         orientation: Qt.Vertical
4     }

 

转载请注明出处:http://surfsky.cnblogs.com 

posted @ 2015-02-13 17:57  surfsky  阅读(5884)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3