demo 来自 https://github.com/cjmdaixi/DarkSwitch添加链接描述

文章目录

  • 效果图
  • 核心代码
  • 从中学习到什么
    • Glow
    • RectangularGlow
    • InnerShadow
  • 感谢无私奉献的人

效果图

核心代码

DarkSwitch.qml

import QtQuick 2.7
import QtQuick.Controls 2.2
import QtGraphicalEffects 1.0
import QtQuick.Layouts 1.3Switch {id: controlindicator: Item{id: indicatorItemimplicitWidth: 135implicitHeight: 58x: control.leftPaddingy: parent.height / 2 - height / 2RectangularGlow {id: effectanchors.fill: boundaryRectglowRadius: 3spread: 0.2color: "black"cornerRadius: boundaryRect.radius + glowRadius}Item {id: srcanchors.fill: boundaryRectRectangle {anchors.centerIn: parentwidth: src.width - 2height: src.height - 2color: "#262626"radius: boundaryRect.radius}}InnerShadow {anchors.fill: srccached: truehorizontalOffset: 0verticalOffset: 0radius: 16samples: 32color: "#000000"smooth: truesource: src}Rectangle{id: boundaryRectanchors.fill: parentanchors.margins: 3border{color: "#515151"; width: 2}radius: 12color: "transparent"}Item{id: handlex: control.checked ? boundaryRect.x + boundaryRect.width - width + 2 : boundaryRect.x - 2y: parent.height / 2 - height / 2width: 70height: boundaryRect.heightBehavior on x{NumberAnimation{duration: 100}}RectangularGlow {id: handleEffectanchors.fill: handleRectglowRadius: 15spread: 0.2color: "#2e91ed"cornerRadius: handleRect.radius + glowRadius}Rectangle {id: handleRectradius: boundaryRect.radiusanchors.fill: parentborder{color: "#2e91ed"; width: 3}gradient: Gradient {GradientStop { position: 0.0; color: "#272727" }GradientStop { position: 0.33; color: "#2e2e2e" }GradientStop { position: 1.0; color: "#0c0c0c" }}}RowLayout{id: vLineRowanchors.centerIn: parentRepeater{model: 3delegate: vLineComp}}Component{id: vLineCompRectangle{id: vLinewidth: 5height: 24gradient: Gradient {GradientStop { position: 0.0; color: "#545454" }GradientStop { position: 1.0; color: "#2b2b2b" }}Rectangle{anchors.centerIn: parentwidth: 3height: 22gradient: Gradient {GradientStop { position: 0.0; color: "#2c2c2c" }GradientStop { position: 0.33; color: "#373737" }GradientStop { position: 1.0; color: "#1b1b1b" }}}}}}}
}

从中学习到什么

  1. 是个Switch类型,重定义Switch的indicator属性。
  2. 蓝色圆角矩形有光晕效果,且是向外发散的,可以采用RectangularGlow来实现。
  3. 黑色凹框有向内的阴影,这个可以用InnerShadow来实现。
  4. 光晕滑块上的黑色填充是渐变的,因此需要使用Rectangle的gradient属性。

Glow

Glow 效果会模糊光源的alpha通道,并使用颜色将其着色,然后将其放置在光源后面,从而在对象周围产生光晕或辉光。模糊边缘的质量可以通过采样samples和半径radius 来控制,发光强度可以通过spread 来改变。
Properties

  • cached : alias
  • color : alias
  • radius : alias
  • samples : alias
  • source :alias
  • spread : alias
  • transparentBorder : alias

Glow 是通过使用高斯模糊实时模糊图像创建的。执行blur live是一项成本高昂的操作。在高端图形硬件上,即使采样数适中,全屏高斯模糊也只能以每秒60帧的速度运行。
注意:使用OpenGL运行时,此效果可用。

RectangularGlow

矩形的Glow

InnerShadow

默认情况下,该效果会生成高质量的阴影图像,因此阴影的渲染速度可能不是最高的。渲染速度会降低,尤其是阴影边缘严重软化时。对于需要更快渲染速度且不需要最高视觉质量的用例,可以将属性 fast设置为true。

Properties

  • cached : bool
  • color : color
  • fast : bool
  • horizontalOffset : real
  • radius : real
  • samples : int
  • source : variant
  • spread : real
  • verticalOffset : real

  import QtQuick 2.12import QtGraphicalEffects 1.12Item {width: 300height: 300Rectangle {anchors.fill: parent}Image {id: butterflysource: "images/butterfly.png"sourceSize: Qt.size(parent.width, parent.height)smooth: truevisible: false}InnerShadow {anchors.fill: butterflyradius: 8.0samples: 16horizontalOffset: -3verticalOffset: 3color: "#b0000000"source: butterfly}}

感谢无私奉献的人

qml 纯代码实现漂亮的switch控件相关推荐

  1. html页面美化代码时间,CSS+JS美化过漂亮的日历控件

    CSS+JS美化过漂亮的日历控件 - www.webdm.cn var months = new Array("一", "二", "三",& ...

  2. php万圣节源码,如何使用纯CSS实现万圣节的toggle控件(附源码)

    本篇文章给大家带来的内容是关于如何使用纯CSS实现万圣节的toggle控件(附源码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 效果预览 源代码地址 https://github ...

  3. android switch 未定义,源生Switch控件在Android4.4无法显示?

    首先,layout.xml代码如下: xmlns:tools="http://schemas.android.com/tools" android:layout_width=&qu ...

  4. Android Switch控件修改样式

    Android中自带的Switch控件在很多时候总觉得和整体系统风格不符,很多时候,自定义Switch是一种方法. 但其实不用这么麻烦,安卓自带的Switch通过修改一些属性,也可以达到和自定义Swi ...

  5. Switch控件的介绍和使用

    写在前面 Switch控件的介绍和使用 先看东西 布局属性介绍 <Switchandroid:id="@+id/mSwitchView"android:theme=" ...

  6. Android 4.0 Switch 控件用源代码实现

    最近项目需要,在4.0 以前的版本上实现一个android 4.0 上的Switch控件,上网找了些例子,都不尽如人意.自己动手,丰衣足食.于是便翻看源码,找到4.0源码中Switch实现的方法.照样 ...

  7. laravel-admin form中的switch控件 不改变状态提交后值为0

    我的个人博客:逐步前行STEP 我把一个字段设默认值为0 需要审核操作 通过设为1 不通过设为2 $states = ['on' => ['value' => 1, 'text' => ...

  8. Switch控件详解

    Switch控件详解 原生效果 5.x 4.x 布局 <Switch android:id="@+id/setting_switch"android:layout_width ...

  9. 推荐三款强大且漂亮的统计图控件

    志在必得(Xuon) 一.免费且强大的Flash统计图--FusionChartsFree 官方网址: http://www.fusioncharts.com/free/ 效果图: 使用感想: 对.N ...

  10. 银弹谷DevSuite零代码开发平台普通窗体控件描述

    零代码开发平台普通窗体控件描述 1.字段控件 2.业务控件 3.通用控件

最新文章

  1. 轻松掌握mysql数据库锁机制的相关原理_轻松掌握MySQL数据库锁机制的相关原理...
  2. 清华大学张悠慧:超越冯·诺依曼模型,实现软硬件去耦合的类脑计算(附视频)
  3. JFreeChart_API
  4. 算法---------宝石与石头
  5. 关于DataAdapter的问题-----Fill: SelectCommand.Connection 属性尚未初始化。
  6. ABAP和Java里关于DEFAULT(默认)机制的一些语言特性
  7. idea使用git插件,出现冲突了怎么解决?多场景分析助你解决问题
  8. python连接hive kerberos_数据库开发实战教程:使用Python连接Kerberos的Presto
  9. 专利基本知识及撰写要求
  10. 少年宫计算机活动总结改进措施,少年宫乒乓球的活动总结
  11. liveness探测mysql,详解k8s中的liveness和readiness的原理和区别
  12. 云计算入门教程普通用户
  13. vue番茄钟 electron打包
  14. ai人工智能的数据服务_AI如何帮助提高企业数据质量
  15. Java WebSocket 基础 建立端点
  16. R循环有两个_海德汉数控系统G代码、M代码、循环大全
  17. 大数据开发中HBase高级特性和rowkey设计分析
  18. 从零开始设计开发优惠券系统
  19. 傲慢与偏见之 - 山寨与创新
  20. 今天,国外AI大厂破产,中国AI企业获18亿元融资!评论区炸了

热门文章

  1. 用 HTML 做一个表单模板
  2. 租船题库整理-判断、选择
  3. MySQL报Out of sort memory, consider increasing server sort buffer size的两种情况
  4. sudo: no valid sudoers sources found, quitting
  5. 全球及中国生物制药产业盈利现状及竞争格局展望报告2021-2027年
  6. 格拉姆矩阵(Gram matrix)详细解读
  7. 肠道菌群失调与炎症性肠病的关联
  8. 前端框架系列之(mvp)
  9. Swift:一个简单的货币转换器App在iOS10中的分析和完善
  10. 电脑变WIFI:建立虚拟共享WIFI热点可查看WIFI密码windows中使用bat批处理命令提示符cmd创建教程含工具