如何实现使用QtQuick循环轮播图,并支持用户滑动切换
来源:互联网 发布:交大网络教育学院网址 编辑:程序博客网 时间:2024/06/06 17:44
1 建立一个 QtQuick工程
2 在生成的main.qml中,改成如下的:
import QtQuick2.6
import QtQuick.Window 2.2
import QtGraphicalEffects 1.0
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
//MainForm {
//anchors.fill: parent
//mouseArea.onClicked: {
// Qt.quit();
//}
//}
3 然后添加上下面的:(Part3来源:Jason )
Flickable {
id: flickableForImage
z: 6
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: 3
width: parent.width
height: (width / 375) * 135
contentWidth: width * 3
contentHeight: height
onMovementStarted: {
timerForImage.running = false;
animationForContenX.running = false;
}
timerForImage.running = false;
animationForContenX.running = false;
}
onMovementEnded: {
timerForImage.running = true;
animationForContenX.duration = 500;
timerForImage.running = true;
animationForContenX.duration = 500;
var a = Math.abs( contentX - 0 );
var b = Math.abs( contentX - width );
var c = Math.abs( contentX - (width * 2) );
var d = Math.min( a, b, c );
var b = Math.abs( contentX - width );
var c = Math.abs( contentX - (width * 2) );
var d = Math.min( a, b, c );
if ( a == d)
{
animationForContenX.to = 0;
animationForContenX.running = true;
}
else if( b == d )
{
animationForContenX.to = width;
animationForContenX.running = true;
}
else if (c == d )
{
animationForContenX.to = width * 2;
animationForContenX.running = true;
}
}
{
animationForContenX.to = 0;
animationForContenX.running = true;
}
else if( b == d )
{
animationForContenX.to = width;
animationForContenX.running = true;
}
else if (c == d )
{
animationForContenX.to = width * 2;
animationForContenX.running = true;
}
}
onWidthChanged: {
if ( animationForContenX.running )
{
return;
}
if ( animationForContenX.running )
{
return;
}
contentX = 0;
}
}
onHeightChanged: {
if ( animationForContenX.running )
{
return;
}
if ( animationForContenX.running )
{
return;
}
contentX = 0;
}
}
Timer {
id: timerForImage
interval: 6000
running: !pageForLogin.visible
repeat: true
id: timerForImage
interval: 6000
running: !pageForLogin.visible
repeat: true
onTriggered: {
animationForContenX.running = false;
animationForContenX.duration = 1000;
animationForContenX.running = false;
animationForContenX.duration = 1000;
if ( flickableForImage.contentX <= 0 )
{
animationForContenX.to = width;
animationForContenX.running = true;
}
else if ( flickableForImage.contentX <= width )
{
animationForContenX.to = width * 2;
animationForContenX.running = true;
}
else
{
animationForContenX.to = 0;
animationForContenX.running = true;
}
}
}
{
animationForContenX.to = width;
animationForContenX.running = true;
}
else if ( flickableForImage.contentX <= width )
{
animationForContenX.to = width * 2;
animationForContenX.running = true;
}
else
{
animationForContenX.to = 0;
animationForContenX.running = true;
}
}
}
NumberAnimation {
id: animationForContenX
target: flickableForImage
property: "contentX"
easing.type: Easing.OutCubic
}
id: animationForContenX
target: flickableForImage
property: "contentX"
easing.type: Easing.OutCubic
}
Item {
width: parent.width
height: parent.height
width: parent.width
height: parent.height
Image {
width: parent.width / 3
height: parent.height
source: "qrc:/Mobile/Menu/TitleImage1.jpg"
}
width: parent.width / 3
height: parent.height
source: "qrc:/Mobile/Menu/TitleImage1.jpg"
}
Image {
x: (parent.width / 3) * 1
width: parent.width / 3
height: parent.height
source: "qrc:/Mobile/Menu/TitleImage2.jpg"
}
x: (parent.width / 3) * 1
width: parent.width / 3
height: parent.height
source: "qrc:/Mobile/Menu/TitleImage2.jpg"
}
Image {
x: (parent.width / 3) * 2
width: parent.width / 3
height: parent.height
source: "qrc:/Mobile/Menu/TitleImage3.jpg"
}
}
x: (parent.width / 3) * 2
width: parent.width / 3
height: parent.height
source: "qrc:/Mobile/Menu/TitleImage3.jpg"
}
}
RectangularGlow {
anchors.fill: parent
z: -1
width: parent.width
height: parent.height
glowRadius: 2
spread: 0.22
color: "#30000000"
}
}
}anchors.fill: parent
z: -1
width: parent.width
height: parent.height
glowRadius: 2
spread: 0.22
color: "#30000000"
}
}
4 QML类型说明-Flickable
ImportStatement: import QtQuick 2.2
Inherits: Item
InheritedBy: GridView and ListView.
1 0
- 如何实现使用QtQuick循环轮播图,并支持用户滑动切换
- 使用ViewFlipper实现图片自动切换,并支持手势滑动切换
- 使用FragmentTabHost实现仿QQ的切换,并在里面嵌套TabLayout+ViewPager的滑动切换
- 使用Fragment实现底部菜单栏功能,并实现左右滑动切换
- ViewPager的使用,并在用户未滑动View时,每隔5s钟自动切换到下一个View
- 使用ViewFlow实现无限循环轮播图和滑动冲突解决
- ViewPager实现无限循环切换和手势滑动效果
- unity数据持久化-如何保存多个帐号密码并切换任意用户实现登陆
- 使用ViewPager实现左右循环滑动
- 使用ViewPager实现左右循环滑动图片
- 使用ViewPager实现左右循环滑动 总结
- 使用ViewPage实现无缝左右循环滑动
- 使用ViewPager实现左右循环滑动
- 使用ViewPager实现左右循环滑动
- 使用ViewPager实现左右循环滑动图片
- 使用ViewPager实现左右循环滑动及滑动跳转
- 如何在Fragment中使用ViewPager,并实现导航随手势滑动效果
- 如何在Fragment中使用ViewPager,并实现导航随手势滑动效果
- JPA介绍及persistence.xml配置介绍
- TCP/IP滑动窗口
- js判断不能为空
- Java面试题第(1)季
- Android 获取你手机中安装的应用的包名及启动页
- 如何实现使用QtQuick循环轮播图,并支持用户滑动切换
- 【转】经验分享:CSS浮动(float,clear)通俗讲解
- html+css小技巧大用处
- MyBatis拦截器
- 版本回退
- grok 官方文档
- iOS 25个性能优化/内存优化常用方法
- iOS-相机,相册,位置访问权限设置
- 给 Android 开发者的 RxJava 详解