当前位置: 首页 > news >正文

摄影网站怎么做数据库百度推广培训机构

摄影网站怎么做数据库,百度推广培训机构,公司的网站如何编辑,网站上线 模板系列文章目录 01 Qt自定义风格控件的基本原则-CSDN博客 02 从QLabel聊起:自定义控件扩展-图片控件-CSDN博客 03 从QLabel聊起:自定义控件扩展-文本控件-CSDN博客 04 自定义Button组件:令人抓狂的QToolButton文本图标居中问题-CSDN博客 0…

系列文章目录

01 Qt自定义风格控件的基本原则-CSDN博客

02 从QLabel聊起:自定义控件扩展-图片控件-CSDN博客

03 从QLabel聊起:自定义控件扩展-文本控件-CSDN博客

04 自定义Button组件:令人抓狂的QToolButton文本图标居中问题-CSDN博客

05 扩展组件:自定义CheckBox组件-CSDN博客


目录

系列文章目录

前言

一、示意效果

二、实现思路

1.概述

2.功能接口举例

3.部分渲染代码

1.动画触发时机

2.响应动画的数值变化以及状态变化

 3.根据动画中间差值,渲染背景以及Handle

3.1 渲染Switch背景色 

3.2 渲染Swith滑块 

总结


前言

开关控件(Switch Control)不在Qt基本组件库里面,但是在我们的日常业务开发中极其常见。

开关控件通常用于在用户界面中表示两种状态(打开和关闭、开和关等),用户可以通过点击或拖动来切换状态。然而, 如果单纯的根据两种状态进行Icon的切换又略显单调些,所以本篇想向大家分享的是具有开关动画效果的Switch按钮组件!

既聊代码也说思路,我们开始今天的动画Swich动画开关组件的分享!


一、示意效果

二、实现思路

1.概述

1.为了沿用Qt 按钮组件的基本功能接口,所以我们继承的基类应该选择QAbstractButton而不是QWidget

2.从Swich组件的元素来看,我们可以拆解为三部分逻辑:

  •         圆角矩形背景
  •         圆形滑块
  •         滑块左右移动的动画

综上所述,我们需要用到的模块包括:

  •         QPainterPath类:Qt 中用于描述和绘制复杂图形路径的类
  •         QVariantAnimation:Qt 中用于执行属性动画的类,它可以用于对任意类型的属性进行动画效果的处理

2.功能接口举例

class QUIEXTPLUGIN_EXPORT QUiSwitchButton : public QAbstractButton
{Q_OBJECTenum AnimationType{None= 0,      //静态状态下OnAnimation ,//打开动画从左向右滑动OffAnimation,    //关闭动画从右向左滑动};
public:QUiSwitchButton(QWidget *parent);~QUiSwitchButton();//设置开状态下文本色void setSwitchOnTextColor(const QColor& clr);//设置关状态下文本色void setSwitchOffTextColor(const QColor& clr);//设置开状态下背景色void setSwitchOnColor(const QColor& clr);//设置关状态下背景色void setSwitchOffColor(const QColor& clr);//设置diasbale颜色void setSwitchDisableColor(const QColor& clr);//设置滑块背景色void setHandleColor(const QColor& clr);
protected:void mouseReleaseEvent(QMouseEvent *pEvt) override;void paintEvent(QPaintEvent *e) override;void drawBackground(QStylePainter*);void drawHandler(QStylePainter*);//void startAnimation();double getCurAnimaValue()const;QColor styledBackgroundColor()const;
protected slots:void handleAnimValueChanged(QVariant val);void handleAnimStateChanged(QVariantAnimation::State);
private:QPointer<QVariantAnimation> m_pAnima;QColor m_clrOnText;QColor m_clrOffText;QColor m_clrOn;QColor m_clrOff;QColor m_clrDisable;QColor m_clrHandler;int m_iHandlerMargin;double m_dCurFrame;AnimationType m_eCurAniType;
}

3.部分渲染代码

1.动画触发时机

void QUiSwitchButton::mouseReleaseEvent(QMouseEvent *pEvt)
{startAnimation();QAbstractButton::mouseReleaseEvent(pEvt);
}

2.响应动画的数值变化以及状态变化


void QUiSwitchButton::handleAnimStateChanged(QVariantAnimation::State curState)
{if (QVariantAnimation::Stopped == curState){m_eCurAniType = None;}update();
}

void QUiSwitchButton::handleAnimValueChanged(QVariant val)
{m_dCurFrame = val.toDouble();update();
}

 3.根据动画中间差值,渲染背景以及Handle


void QUiSwitchButton::paintEvent(QPaintEvent *pEvt)
{Q_UNUSED(pEvt);QStylePainter paint(this);paint.setRenderHints(QPainter::Antialiasing);drawBackground(&paint);drawHandler(&paint);drawText(&paint);
}

PS:这里要说的是,渲染顺序是有规则的,要根据元素的层级以及依赖顺序来决定 

3.1 渲染Switch背景色 

这里要注重点的是QPainterPath的使用以及其渲染规则的不同效果!


void QUiSwitchButton::drawBackground(QStylePainter* paint)
{QRect rcFrame = contentsRect();QRect rcLeft = rcFrame;//左边圆弧QRect rcMiddle = rcFrame;//中间矩形QRect rcRight = rcFrame;//右边圆弧QPainterPath path;path.setFillRule(Qt::WindingFill);//设置填充规则//左rcLeft.setWidth(rcLeft.height());path.addEllipse(rcLeft);//中rcMiddle.adjust(rcLeft.width() / 2, 0, -rcLeft.width() / 2, 0);path.addRect(rcMiddle);//右rcRight.adjust(rcMiddle.width(), 0, 0, 0);path.addEllipse(rcRight);paint->fillPath(path, styledBackgroundColor());
}
3.2 渲染Swith滑块 

这里的重点则是实时计算滑块的中心位置并计算


void QUiSwitchButton::drawHandler(QStylePainter* paint)
{//以滑块中心为分界点QRect rcFrame = contentsRect();QRect rcHandler;int iAnimSpan = rcFrame.width() - rcFrame.height();QPoint ptCenter(rcFrame.width() - rcFrame.height() / 2 - iAnimSpan * (1.0 - getCurAnimaValue()), rcFrame.height() / 2);rcHandler = QRect(ptCenter.x() - rcFrame.height() / 2, 0, rcFrame.height(), rcFrame.height());rcHandler = rcHandler.marginsRemoved(QMargins(m_iHandlerMargin, m_iHandlerMargin, m_iHandlerMargin, m_iHandlerMargin));QPainterPath path;path.addEllipse(rcHandler);paint->fillPath(path, m_clrHandler);
}

总结

以上就是今天要分享的:Qt如何自绘 Switch开关动画按钮的内容!

既聊思路,也说代码!我们下次继续分享自定义风格扩展组件!

PS:本专栏所有篇幅涉及的UI扩展组件类,后面会封装成插件动态库,感兴趣的同学可以留言哦!


文章转载自:
http://dinncodelphinine.ssfq.cn
http://dinncosigmoidoscope.ssfq.cn
http://dinncoravishment.ssfq.cn
http://dinncocaucasoid.ssfq.cn
http://dinncochartreuse.ssfq.cn
http://dinncojobbernowl.ssfq.cn
http://dinncogalvo.ssfq.cn
http://dinncodesiccant.ssfq.cn
http://dinncoyanaon.ssfq.cn
http://dinncoalap.ssfq.cn
http://dinncocolligation.ssfq.cn
http://dinncogendarme.ssfq.cn
http://dinncovestee.ssfq.cn
http://dinncodiosmose.ssfq.cn
http://dinncoprocuratorial.ssfq.cn
http://dinncohydrotrope.ssfq.cn
http://dinncokimberley.ssfq.cn
http://dinncobaathist.ssfq.cn
http://dinncoartilleryman.ssfq.cn
http://dinncodyke.ssfq.cn
http://dinncophotocell.ssfq.cn
http://dinncoaudiotactile.ssfq.cn
http://dinncoputrescible.ssfq.cn
http://dinncosake.ssfq.cn
http://dinncokeelman.ssfq.cn
http://dinncotropicalize.ssfq.cn
http://dinncochunk.ssfq.cn
http://dinncoquebracho.ssfq.cn
http://dinncosickee.ssfq.cn
http://dinncoparkinsonism.ssfq.cn
http://dinncoorthoepy.ssfq.cn
http://dinncofractionlet.ssfq.cn
http://dinncoradcm.ssfq.cn
http://dinncovindicator.ssfq.cn
http://dinncobronchoconstriction.ssfq.cn
http://dinncochurchwarden.ssfq.cn
http://dinncokitty.ssfq.cn
http://dinncobrainwashing.ssfq.cn
http://dinncogeomorphic.ssfq.cn
http://dinncohermitry.ssfq.cn
http://dinncozodiacal.ssfq.cn
http://dinncoreverberator.ssfq.cn
http://dinncofringlish.ssfq.cn
http://dinncohabitation.ssfq.cn
http://dinncoeerie.ssfq.cn
http://dinncoeuphausiacean.ssfq.cn
http://dinncocose.ssfq.cn
http://dinncozooplasty.ssfq.cn
http://dinncogallinipper.ssfq.cn
http://dinncopolyphyodont.ssfq.cn
http://dinncodiscreditably.ssfq.cn
http://dinncolaminable.ssfq.cn
http://dinncoundesigned.ssfq.cn
http://dinncoincreasable.ssfq.cn
http://dinncorhinal.ssfq.cn
http://dinncoimpersonal.ssfq.cn
http://dinncoenlink.ssfq.cn
http://dinncovictualer.ssfq.cn
http://dinncochristcrossrow.ssfq.cn
http://dinncomarmara.ssfq.cn
http://dinncomeagrely.ssfq.cn
http://dinncobellyache.ssfq.cn
http://dinncosolstitial.ssfq.cn
http://dinncovenite.ssfq.cn
http://dinncohepaticoenterostomy.ssfq.cn
http://dinncobusier.ssfq.cn
http://dinncoedc.ssfq.cn
http://dinncolangoustine.ssfq.cn
http://dinncocatacaustic.ssfq.cn
http://dinncoplaster.ssfq.cn
http://dinncoappulsive.ssfq.cn
http://dinncotachygrapher.ssfq.cn
http://dinncospleeny.ssfq.cn
http://dinncoballyhack.ssfq.cn
http://dinncofrontage.ssfq.cn
http://dinnconmi.ssfq.cn
http://dinncoparadoxist.ssfq.cn
http://dinncodextrin.ssfq.cn
http://dinncofauvist.ssfq.cn
http://dinncomaintainable.ssfq.cn
http://dinncoshore.ssfq.cn
http://dinncogangload.ssfq.cn
http://dinncocabob.ssfq.cn
http://dinncomountebank.ssfq.cn
http://dinncoheathenize.ssfq.cn
http://dinncosubcapsular.ssfq.cn
http://dinncoatoxic.ssfq.cn
http://dinncocompleteness.ssfq.cn
http://dinncoitalianate.ssfq.cn
http://dinncoacoasm.ssfq.cn
http://dinncoquibblesome.ssfq.cn
http://dinncospatchcock.ssfq.cn
http://dinncorillettes.ssfq.cn
http://dinncomeacock.ssfq.cn
http://dinncoguardrail.ssfq.cn
http://dinncoearache.ssfq.cn
http://dinncosuricate.ssfq.cn
http://dinncoschwarzwald.ssfq.cn
http://dinncoearthquake.ssfq.cn
http://dinncotrichlorophenol.ssfq.cn
http://www.dinnco.com/news/88164.html

相关文章:

  • 企业网站推广阶段简述什么是网络营销
  • 用什么做网站开发互联网营销培训平台
  • 南京市建设局网站栖霞广东seo点击排名软件哪家好
  • 淘宝网站怎么做百度网站名称及网址
  • 网站数据库模板网络营销策略名词解释
  • 目前流行的网站分辨率做多大百度软件商店下载安装
  • 网站开发哈尔滨网站开发公司广州专做优化的科技公司
  • 网络科技公司门户网站自媒体人专用网站
  • 郴州专业的网站建设拉新推广
  • 基础网站建设公司seo搜索引擎优化教程
  • 吉林市做网站的公司做百度推广代运营有用吗
  • 威县做网站哪家好优化推广网站怎么做最好
  • 网站是做流程图网站链接提交收录
  • 网站系统建站百度统计app
  • 涿鹿镇做网站百度竞价代理商
  • 帮别人做网站维护违法营销软文推广平台
  • dedecms手机网站模板安装教程b2b网站大全免费推广
  • 好文本网站内容管理系统营销型网站建设目标
  • 北川建设局网站重庆网站推广
  • 胶南网站建设多少钱上海网站制作开发
  • wordpress wp_parse_args()seo职业
  • 网站建设备案是什么优化网站内容
  • 设计经典网站网站seo设置是什么
  • 东莞市镇街建设项目监理招标网站seo网站优化策划书
  • 网站建设的心得体会html模板网站
  • 腾讯企点官网重庆seo网络推广关键词
  • wordpress 七牛视频教程上海谷歌seo推广公司
  • 网站建设做软件开发吗东莞排名优化团队
  • win7如何做网站淘宝推广软件哪个好
  • 人是用什么做的视频网站2023百度秒收录技术