QML控件类型:PageIndicator

一、描述

页面指示器。用于在多个页面的容器中指示当前活动的页面。由呈现页面的委托项目组成。

Column {
    StackLayout {
        id: stackLayout

        Page {
            // ...
        }
        Page {
            // ...
        }
        Page {
            // ...
        }
    }

    PageIndicator {
        currentIndex: stackLayout.currentIndex
        count: stackLayout.count
    }
}

二、属性成员

1、count : int

总页数。

2、currentIndex : int

当前页的索引。

3、delegate : Component

一个呈现页的委托。

以下属性在每个委托的上下文中可用:

  • index : int:项目的索引
  • press : bool:项目是否被按下

4、interactive : bool

控件是否是交互式的。默认为 false。

交互式页面指示器对按下作出反应并自动适当地更改当前索引。

页面指示器一般非常小(为了避免分散用户对用户界面实际内容的注意力),可能很难点击,并且可能不容易被用户识别为交互的。因此最好被用作主要的导航控件的补充。

SwipeView {
    id: view
    currentIndex: pageIndicator.currentIndex
    anchors.fill: parent

    Page {
        title: qsTr("Home")
    }
    Page {
        title: qsTr("Discover")
    }
    Page {
        title: qsTr("Activity")
    }
}

PageIndicator {
    id: pageIndicator
    interactive: true
    count: view.count
    currentIndex: view.currentIndex

    anchors.bottom: parent.bottom
    anchors.horizontalCenter: parent.horizontalCenter
}

三、 自定义 PageIndicator 示例

import QtQuick
import QtQuick.Controls

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    PageIndicator {
        id: control
        count: 5
        currentIndex: 2

        delegate: Rectangle {
            implicitWidth: 8
            implicitHeight: 8

            radius: width / 2
            color: "#21be2b"

            opacity: index === control.currentIndex ? 0.95 : pressed ? 0.7 : 0.45

            required property int index

            Behavior on opacity {
                OpacityAnimator {
                    duration: 100
                }
            }
        }
    }
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值