QMl 组件(一)

QML 自定义插件之轮播

效果如下
在这里插入图片描述

组件代码如下所示

import QtQuick 2.12
import QtQuick.Controls 2.5

Rectangle {
    width: parent.width
    height: parent.height
    SwipeView {
          id: view
          currentIndex: 0
          anchors.fill: parent
          Page{
              Image{
                  anchors.fill: parent
                  source: "qrc:/image/logo2.jpg"
              }
          }
          Page{
              Image{
                  anchors.fill: parent
                  source: "qrc:/image/logo4.jpg"
              }
          }
          Page{
              Image{
                  anchors.fill: parent
                  source: "qrc:/image/logo6.jpg"
              }
          }
          Item {
              Image{
                  anchors.fill: parent
                  source: "qrc:/image/logo8.jpg"
              }
          }
          Item {
              id: secondPage
              Rectangle{
                  anchors.centerIn: parent
                  width: 200
                  height: 200
                  color: "black"
              }
          }
      }

    //数字显示(与原点显示二选一)
    Rectangle{
     width: 60
     height: 20
     radius: height / 2
     color: "#858585"
     anchors.bottom: view.bottom
     anchors.right: parent.right
     Text {
         id: _numIndicatorText
         anchors.centerIn: parent
         font.family: fontFamily
         font.pixelSize: 14
         color: "#FFFFFF"
         text: qsTr((view.currentIndex + 1) +  "/" + view.count)
     }
    }
    //原点显示
    PageIndicator {
        id: indicator
        interactive: true
        count: view.count
        currentIndex: view.currentIndex
        anchors.bottom: view.bottom
        anchors.horizontalCenter: parent.horizontalCenter
        delegate: Rectangle {
            implicitWidth: 8
            implicitHeight: implicitWidth
            radius: width / 2
            color: index === indicator.currentIndex ? "red" : "#858585"
            opacity: index === indicator.currentIndex ? 1 : pressed ? 0.7 : 0.3
            anchors.verticalCenter: parent.verticalCenter
            Behavior on opacity {
                OpacityAnimator {
                    duration: 1000
                }
            }
        }
    }

      Timer {
          interval: 1500; running: true; repeat: true
          onTriggered: {
              if(view.currentIndex < view.count - 1) view.currentIndex++;
                                      else view.currentIndex = 0;
          }
      }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值