一、效果展示

  效果如图1所示,时钟列表支持鼠标左右拖动,带有黑色背景的是晚上时钟,无黑色背景的是白天时钟

二、源码分析

1、main.cpp文件中只包含了一个宏,该宏的具体解释请看qml 示例中的关键宏文章

2、时钟项

 Item {
id : clock
width: {
if (ListView.view && ListView.view.width >= )
return ListView.view.width / Math.floor(ListView.view.width / 200.0);
else
return ;
} height: {
if (ListView.view && ListView.view.height >= )
return ListView.view.height;
else
return ;
} property alias city: cityLabel.text//属性别名,方便在外部使用
property int hours//自定义属性
property int minutes
property int seconds
property real shift
property bool night: false//是否是晚上 来决定是否显示黑色实心圈
property bool internationalTime: true //Unset for local time //js函数
function timeChanged() {
var date = new Date;
hours = internationalTime ? date.getUTCHours() + Math.floor(clock.shift) : date.getHours()
night = ( hours < || hours > )
minutes = internationalTime ? date.getUTCMinutes() + ((clock.shift % ) * ) : date.getMinutes()
seconds = date.getUTCSeconds();
} Timer {
interval: ; running: true; repeat: true;//一个每隔100ms重复执行的定时器,默认启动
onTriggered: clock.timeChanged()//定时器槽函数
} Item {
anchors.centerIn: parent
width: ; height: Image { id: background; source: "clock.png"; visible: clock.night == false }//最外层白色圈
Image { source: "clock-night.png"; visible: clock.night == true }//黑色实心圈,带有白色实心圆球的刻度点 //时针
Image {
x: 92.5; y:
source: "hour.png"
transform: Rotation {
id: hourRotation
origin.x: 7.5; origin.y: ;
angle: (clock.hours * ) + (clock.minutes * 0.5)
Behavior on angle {
SpringAnimation { spring: ; damping: 0.2; modulus: }
}
}
} //分针
Image {
x: 93.5; y:
source: "minute.png"
transform: Rotation {
id: minuteRotation
origin.x: 6.5; origin.y: ;
angle: clock.minutes *
Behavior on angle {
SpringAnimation { spring: ; damping: 0.2; modulus: }
}
}
} //秒针
Image {
x: 97.5; y:
source: "second.png"
transform: Rotation {
id: secondRotation
origin.x: 2.5; origin.y: ;
angle: clock.seconds *
Behavior on angle {
SpringAnimation { spring: ; damping: 0.2; modulus: }
}
}
}
//中心白色圆圈
Image {
anchors.centerIn: background; source: "center.png"
} Text {
id: cityLabel//该属性已经被导出,在clocks.qml文件中指定该属性值
y: ; anchors.horizontalCenter: parent.horizontalCenter
color: "white"
font.family: "Helvetica"
font.bold: true; font.pixelSize:
style: Text.Raised; styleColor: "black"
}
}
}

3、时钟列表

 import "content" as Content  //导入目录  该目录底下的所有qml自定义控件均可以直接使用

 Rectangle {
id: root
width: ; height:
color: "#646464" ListView {//列表视图
id: clockview//唯一id
anchors.fill: parent//填充整个父窗口
orientation: ListView.Horizontal//列表朝向为水平方向
cacheBuffer: //左右2000个像素以内的委托项都不会被析构
snapMode: ListView.SnapOneItem//拖拽模式
highlightRangeMode: ListView.ApplyRange//高亮模式,高亮尽可能在可是区间内 delegate: Content.Clock { city: cityName; shift: timeShift }//设置Clock控件的导出属性值
model: ListModel {//静态model
ListElement { cityName: "New York"; timeShift: - }
ListElement { cityName: "London"; timeShift: }
ListElement { cityName: "Oslo"; timeShift: }
ListElement { cityName: "Mumbai"; timeShift: 5.5 }
ListElement { cityName: "Tokyo"; timeShift: }
ListElement { cityName: "Brisbane"; timeShift: }
ListElement { cityName: "Los Angeles"; timeShift: - }
}
}
//左下角上一个箭头
Image {
anchors.left: parent.left
anchors.bottom: parent.bottom
anchors.margins:
source: "content/arrow.png"
rotation: -
opacity: clockview.atXBeginning ? : 0.5//当视图滚动到第一个时透明度为0(使用行为动画)
Behavior on opacity { NumberAnimation { duration: } }//在透明度属性上添加动画(数字动画)
}
//右下角下一个箭头
Image {
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins:
source: "content/arrow.png"
rotation:
opacity: clockview.atXEnd ? : 0.5
Behavior on opacity { NumberAnimation { duration: } }
}
}

qml demo分析(clocks-时钟)的更多相关文章

  1. qml demo分析(threadedanimation-线程动画)

    一.效果预览 使用过qml的同学都知道,使用qml做动画效果是非常简单的,再也不需要像QWidget那样,自己模拟一个动画,费时又费力,往往还达不到效果.今天我们就来分析下qml的两种动画实现方式,如 ...

  2. qml demo分析(maskedmousearea-异形窗口)

    一.效果展示 如本文的标题所示,这篇文章分析的demo是一个异形窗口,主要展示鼠标在和异形区域交互的使用,效果如图1所示,当鼠标移动到白云或者月亮上时,相应的物体会高亮,当鼠标按下时,物体会有一个放大 ...

  3. qml demo分析(maroon-小游戏)

    1.效果展示 这篇文章我还是分析一个qt源码中的qml程序,程序运行效果如下图所示. 图1  游戏开始 图2  游戏中 2.源码分析 这个游戏的源码文件比较多,为了能更清楚的了解整个代码,我先整体分析 ...

  4. qml demo分析(abstractitemmodel-数据分离)

    一.概述 qt5之后qml也可以被用于桌面程序开发,今天我就拿出qt demo中的一个qml示例程序进行分析.这个demo主要是展示了qml数据和展示分离的使用方式,qml只专注于快速高效的绘制界面, ...

  5. qml demo分析(externaldraganddrop-拖拽)

    一.效果展示 客户端程序拖拽是一个很常见的需求,对于QWidget程序来说,需要重写如图1这么几个方法,通过重写这几个方法的逻辑,我们就可以控制鼠标拖拽的逻辑,糟糕的是QDrag执行exec后是一个阻 ...

  6. qml demo分析(threading-线程任务)

    一.关键类说明 qml内置了WorkerScript组件,该组件有一个source属性,可以加载js文件,含有一个名为message的信号,意味着他有一个默认的onMessage槽函数,除此之外他还有 ...

  7. qml demo分析(text-字体展示)

    上一篇文章分析了一个小游戏,使用qml编写界面+js进行复杂逻辑控制,算是一个比较完整的qml示例代码了,今天就不那么继续变态啦,来看一个简单的字体示例程序吧,该示例代码比较简单,主要是展示了几个简单 ...

  8. qml demo分析(samegame-拼图游戏)

    一.效果展示 相信大家都玩儿过连连看游戏,而且此款游戏也是闲时一款打发时间的趣事,那么接下来我将分析一款类似的游戏,完全使用qml编写界面,复杂逻辑使用js完成.由于此游戏包含4种游戏模式,因此本篇文 ...

  9. qml demo分析(rssnews-常见新闻布局)

    一.效果展示 今儿来分析一篇常见的ui布局,完全使用qml编写,ui交互效果友好,如图1所示,是一个常见的客户端新闻展示效果,左侧是一个列表,右侧是新闻详情. 图1 新闻效果图 二.源码分析 首先先来 ...

随机推荐

  1. 从零开始学习 Docker

      这篇文章是我学习 Docker 的记录,大部分内容摘抄自 <<Docker - 从入门到实践>> 一书,并非本人原创.学习过程中整理成适合我自己的笔记,其中也包含了我自己的 ...

  2. Python中标准模块importlib详解

    1 模块简介 Python提供了importlib包作为标准库的一部分.目的就是提供Python中import语句的实现(以及__import__函数).另外,importlib允许程序员创建他们自定 ...

  3. 解决jQuery的$符号的冲突问题

    强大的jQuery框架在设计的时候不仅考虑到自己的符号定义问题,还想到了与其他框架的和平共处问题,(给别人留条路也是写在给自己留路),设计者以博大的胸怀和包罗万象的设计理念赋予了jq顽强的生命力. 废 ...

  4. BinaryOperator<T>接口的用法示例+BiFunction

    转自http://www.tpyyes.com/a/java/2017/1015/285.html 转自https://blog.csdn.net/u014331288/article/details ...

  5. baseFileWriter.go

    package blog4go import ( "fmt" "os" "sync" "time" ) const ( ...

  6. BZOJ_2124_等差子序列_线段树+Hash

    BZOJ_2124_等差子序列_线段树+Hash Description 给一个1到N的排列{Ai},询问是否存在1<=p1<p2<p3<p4<p5<…<pL ...

  7. springboot2.x里面访问静态资源的坑

    在spring boot的自定义配置类继承 WebMvcConfigurationSupport 后,发现自动配置的静态资源路径( classpath:/META/resources/,classpa ...

  8. HTTP 视频怎么在 MIP 页面中使用?

    在 MIP 中,一些资源的使用需要支持 HTTPS,视频就是其中一种.但目前大部分站点的视频资源都还是 HTTP 的资源,无法在百度 MIP 搜索结果中直接使用, mip-video 视频组件针对 H ...

  9. Python爬虫入门教程 55-100 python爬虫高级技术之验证码篇

    验证码探究 如果你是一个数据挖掘爱好者,那么验证码是你避免不过去的一个天坑,和各种验证码斗争,必然是你成长的一条道路,接下来的几篇文章,我会尽量的找到各种验证码,并且去尝试解决掉它,中间有些技术甚至我 ...

  10. 【Python3爬虫】最新的模拟登录新浪微博教程

    一.写在前面 首先呢,由于之前重装系统,又要重新配置环境,然后还有一些别的事,导致我一直没有写爬虫了,不过现在又可以继续写了. 然后我这次说的模拟登录新浪微博呢,不是使用Selenium模拟浏览器操作 ...