qml: 另类图像轮播;
一般来说,图像轮播都是采用ListView等model进行设计, 比较方便。 这里展示我自己设计的图像轮播
方案, 仅采用两个QImage实现;
下面展示代码以及简述:(注: 以下代码为本人原创, 如需要应用于商业,请留言通知!)
import QtQuick 2.0
import QtQuick.Window 2.3
import QtQuick.Controls 1.4
import MaterialUI 1.0
import com.Advertisement 1.0
AppWindow{
id: adverpage;
flags:Qt.FramelessWindowHint;
bDomal: true;
x: (Screen.desktopAvailableWidth - width)/2;
y: (Screen.desktopAvailableHeight - height)/2; QtObject{
id:__inter;
property var advertises: adver.avertises;
property real index: -1;
property real time: 20; //广告时间; //找到下一个;
property var firstImg : img1.x == 0? img2: img1;
property var secondImg : img1.x == 0 ?img1: img2;
property var firstMove : img1.x == 0? img2Moving: img1Moving;
property var secondMove : img1.x == 0? img1Moving: img2Moving;
property var nextIndex: index+1 >= advertises.length ? 0: index + 1; //得到下一个序号;
} function play()
{
//初始化;
__inter.index++;
if( __inter.advertises.length >= 2)
{
if( Qt.platform.os == "windows")
{
img1.source = "file:///" + __inter.advertises[__inter.index];
img2.source = "file:///" + __inter.advertises[__inter.nextIndex];
}else{
img1.firstImg.source = __inter.advertises[__inter.index];
img2.source = __inter.advertises[__inter.nextIndex];
}
}
remainTime.text = __inter.time.toString() + " 秒";
timer.start();
} function stop()
{
timer.stop();
adverpage.close();
} function scroll()
{
__inter.time--; //时间更新;
remainTime.text = __inter.time.toString() + " 秒";
if( __inter.time > 0 )
{
console.log(__inter.advertises[__inter.index]);
if( Qt.platform.os == "windows")
{
__inter.secondImg.source = "file:///" + __inter.advertises[__inter.nextIndex]; //预存图像;
}else{
__inter.secondImg.source = __inter.advertises[__inter.nextIndex];
}
__inter.firstMove.from = 0;
__inter.firstMove.to = -__inter.firstImg.width;
__inter.secondMove.from = __inter.secondImg.width;
__inter.secondMove.to = 0;
__inter.firstMove.start();
__inter.secondMove.start();
}else{
timer.stop();
adverpage.close();
}
__inter.index = __inter.nextIndex; //下一个;
}
Rectangle{
id: scrollArea;
width: img1.x > img2.x? img1.width: img2.width;
height:Math.max(img1.height, img2.height);
clip: true;
Row{
spacing: Global.margin;
z: 2;
anchors{
top: parent.top;
topMargin: Global.margin;
right: parent.right;
rightMargin: Global.margin;
}
Label{ //倒计时以及“关闭广告”功能;
id: remainTime;
width: 50;
height: 20;
color: "red";
font.bold: true;
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
}
Label{
width: 50;
height: 20;
color: "red";
font.bold: true;
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text:qsTr("关闭广告");
MouseArea{
anchors.fill: parent;
onClicked:{
console.log("no right to close");
stop();
}
}
}
} Image {
id:img1
cache: false;
x: 0;
anchors.verticalCenter: parent.verticalCenter;
NumberAnimation{
id: img1Moving;
target: img1
properties: "x"
duration: 300;
}
}
Image{
id: img2;
cache: false;
x: img1.width;
anchors.verticalCenter: parent.verticalCenter;
NumberAnimation{
id: img2Moving;
target: img2
properties: "x"
duration: 300;
}
} MouseArea{ //暂停功能;
anchors.fill: parent;
cursorShape: Qt.PointingHandCursor
onClicked: {
if( timer.running )
timer.stop();
else
timer.restart();
}
}
} Advertisement{ //从本地获取要展示的广告列表;
id: adver;
} Timer{ //定时器,用于轮播;
id: timer;
repeat: true;
interval: 1500;
onTriggered:{
scroll();
}
}
}
qml: 另类图像轮播;的更多相关文章
- jquery的fadeTo方法的淡入淡出轮播图插件
由于对基于jquery的简单插件开发有了一定的了解,慢慢的也对基于jquery的插件开发有了兴趣,在上班结束之后就研究各种插件的思路逻辑.最近开发了一款基于jquery的fadeTo方法的轮播图插件, ...
- Qt编写自定义控件23-广告轮播控件
一.前言 广告轮播这个控件做的比较早,是很早以前定制一个电信客户端时候用到的,该客户端需要在首页展示轮播预先设定好的图片,图片的路径可以自由设定,然后轮播的间隔速度可以自由控制,同时该控件还需要提供两 ...
- CSS3常用属性(边框、背景、文本效果、2D转换、3D转换、过渡、有过渡效果大图轮播、动画)
CSS3边框: 1.CSS3圆角:border-radius 属性--创建边框线的圆角 <body style="font-size:24px; color:#60F;"& ...
- Jquery 轮播图简易框架
=====================基本结构===================== <div class="carousel" style="width: ...
- 12款经典的白富美型—jquery图片轮播插件—前端开发必备
图片轮播是网站中的常用功能,用于在有限的网页空间内展示一组产品图片或者照片,同时还有非常吸引人的动画效果.本文向大家推荐12款实用的 jQuery 图片轮播效果插件,帮助你在你的项目中加入一些效果精美 ...
- 第十篇.bootstrap轮播
使用bootstrap的轮播插件可以向站点添加滑块,内容可以是图像,内嵌框架,视频或其它任何内容,使用轮播插件需要引入bootstrap.min.js. <div id="carous ...
- html+css+javascript实现简易轮播图片
html: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <lin ...
- Nivo Slider - 世界上最棒的 jQuery 图片轮播插件
Nivo Slider 号称世界上最棒的图片轮播插件,有独立的 jQuery 插件和 WordPress 插件两个版本.目前下载量已经突破 1,800,000 次!jQuery 独立版本的插件主要有如 ...
- Android学习笔记之图片轮播...
PS:一个bug又折腾了一个下午....哎... 学习内容: 1.Android利用ViewPager和PagerAdapter实现图片轮播... 2.使用反射机制获取Android的资源信息... ...
随机推荐
- CentOS7 搭建影梭服务器
安装Python包管理工具 yum install python-setuptools && easy_install pip 安装Shadowsocks pip install sh ...
- Nginx用户权限验证管理
首先需要编译进--with-http_request_model 配置指令:auth_request url | off; #url是指上游服务器地址 context: http/location 备 ...
- windoows ftp的自动上传bat
@echo off set P=%cd% #获取脚本当前文件路径 del /f /s /q %P%\tmp.txt set Y=%DATE:~0,4% #获取年 set M=%DATE:~5,2% # ...
- ubuntu 14.04zabbix的安装
开始安装 64位 Ubuntu 14.04.5 LTS \n \l 安装zabbix的源,以下操作在root下进行 # wget http://repo.zabbix.com/zabbix/3.0/ ...
- BZOJ1150[CTSC2007]数据备份Backup——模拟费用流+堆+链表
题目描述 你在一家 IT 公司为大型写字楼或办公楼(offices)的计算机数据做备份.然而数据备份的工作是枯燥乏味 的,因此你想设计一个系统让不同的办公楼彼此之间互相备份,而你则坐在家中尽享计算机游 ...
- Codeforces Round #488 Div. 1
A:枚举每个点判断是否同时在两个正方形中即可. #include<iostream> #include<cstdio> #include<cmath> #inclu ...
- Android InputType
转载: http://blog.csdn.net/wei_zhi/article/details/50094503 在Android开发过程中,我们经常使用到EditText控件,并且会根据各种需求设 ...
- DRF 权限和频率
Django Rest Framework 权限组件 DRF的权限 权限组件源码解析 我们之前说过了DRF的版本和认证~也知道了权限和频率跟版本认证都是在initial方法里初始化的~~ 其实我们版本 ...
- Easy Finding POJ - 3740 (DLX)
显然这是一道dfs简单题 或许匹配也能做 然而用了dancing links 显然这也是一道模板题 好的吧 调了一上午 终于弄好了模板 Easy Finding Time Limit: 1000MS ...
- jqGrid 手册 - 搜索
搜索 类型: colModel Options Toolbar Searching Custom Searching Single field searching Advanced Searching ...