欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 创投人物 > Qt/QML学习-DelayButton

Qt/QML学习-DelayButton

2024/10/24 22:24:29 来源:https://blog.csdn.net/qq1138345424/article/details/140482864  浏览:    关键词:Qt/QML学习-DelayButton

QML学习

  • DelayButton例程
  • 视频讲解
  • 代码

main.qml

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15Window {width: 640height: 480visible: truetitle: qsTr("DelayButton")DelayButton {id: delayButtonx: 10y: 10delay: 1000text: "一键三连"onActivated: {logText.text = "已三连"}onPressed: {logText.text = ""}// 内容视图contentItem: Text {text: delayButton.textanchors.centerIn: delayButtonfont.pointSize: 30}// 背景视图background: Rectangle {color: "transparent"Canvas {anchors.fill: parentonPaint: {draw()}// 动画平滑function draw() {var ctx = getContext("2d")ctx.clearRect(0, 0, width, height)ctx.beginPath()ctx.moveTo(0, 0)drawRect(ctx)ctx.stroke()requestAnimationFrame(draw)}// 画边框function drawRect(ctx) {if (delayButton.progress < 0.25) {ctx.lineTo(width * (delayButton.progress / 0.25), 0)return} else {ctx.lineTo(width, 0)}if (delayButton.progress < 0.5) {ctx.lineTo(width, height * ((delayButton.progress - 0.25) / 0.25))return} else {ctx.lineTo(width, height)}if (delayButton.progress < 0.75) {ctx.lineTo(width * (1 - (delayButton.progress - 0.5) / 0.25), height)} else {ctx.lineTo(0, height)ctx.lineTo(0, height * (1 - (delayButton.progress - 0.75) / 0.25))}}}}}// 演示Text {id: logTextanchors.left: delayButton.rightanchors.verticalCenter: delayButton.verticalCenterleftPadding: 20font.pointSize: 30}
}

演示

  • 视频讲解

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com