QML 自定义控件 Toast

本文介绍如何在QML中创建类似手机的Toast提示功能,包括弹出提示并在设定时间内自动消失的效果,同时提供了`main.qml`和`Toast.qml`两个关键文件的概述。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

QML 仿手机Toast

效果图:弹出提示后,提示框在一定时间内消失。

main.qml

    Button{
        text: "提示框3"
        onClicked: {
            toast.show("天行健 君子以自强不息,地势坤 君子以厚德载物", 4000);
        }
    }
    
    Toast{
        id: toast
    }

Toast.qml

import QtQuick 2.12

Rectangle {
    id: root
    opacity: 0
    color: "black"
    anchors{
        horizontalCenter: parent.horizontalCenter
        bottom: parent.bottom
        bottomMargin: 20
    }
    height: 50
    radius: 25
    antialiasing: true

    Text {
        id: lab
        color: "white"
        wrapMode: Text.Wrap
        horizontalAlignment: Text.AlignHCenter
        font.pixelSize: 16
        anchors.centerIn: parent
    }

    SequentialAnimation on opacity {
        id: animation
 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值