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

java做web网站的流程响应式网站建设

java做web网站的流程,响应式网站建设,网页搜索老是跳到百度怎么办,wordpress繁体版下载概述 使用Qt如何制作一个滑动开关按钮,同类的文章和代码网上很多,但很多都是pyqt编写的,也有c编写的,大家可以参考. 我这里主要是实现了一个滑动按钮,富有滑动动画和文字,话不多说,上代码 自定义…

概述


使用Qt如何制作一个滑动开关按钮,同类的文章和代码网上很多,但很多都是pyqt编写的,也有c++编写的,大家可以参考. 我这里主要是实现了一个滑动按钮,富有滑动动画和文字,话不多说,上代码

自定义滑动按钮

c++/Qt实现


.h文件

#ifndef SwitchButtonInsideINSIDE_H
#define SwitchButtonInsideINSIDE_H#include <QWidget>#include "customcomponent_global.h"class Slider;class CUSTOMCOMPONENT_EXPORT SwitchButtonInside : public QWidget
{Q_OBJECTpublic:explicit SwitchButtonInside(QWidget *parent = nullptr);~SwitchButtonInside();/*** @brief SetSize 设置按钮的尺寸* @param nWidth 按钮的新宽度* @param nHeight 按钮的新高度*/void SetSize(int nWidth, int nHeight);/*** @brief SetActiveColor 设置按钮激活时候的颜色* @param color 激活颜色*/void SetActiveColor(const QColor& color);/*** @brief SetInactiveColor 设置按钮未激活时候的颜色* @param color 未激活颜色*/void SetInactiveColor(const QColor& color);/*** @brief SetSliderColor 设置滑块颜色* @param color 滑块的颜色*/void SetSliderColor(const QColor& color);/*** @brief SetStatus 设置按钮状态* @param bActive true: 激活,false: 未激活*/void SetStatus(bool bActive);/*** @brief GetStatus 获取按钮当前状态* @return  true: 激活,false: 未激活*/bool GetStatus() const;/*** @brief SetStatus 设置按钮显示文字* @param text: 文字内容*/void SetText(const QString &text);protected:void paintEvent(QPaintEvent *event) override;void mousePressEvent(QMouseEvent *event) override;void mouseReleaseEvent(QMouseEvent *event) override;void ToActive();void ToInactive();private:bool m_bActive; // 是否激活int m_nArcRadius; // 圆弧的半径int m_nRectWidth; // 矩形的宽度const short m_nMargin = 2;const int m_nDuration = 100; // 动画时间,单位毫秒bool m_bClicked; // 能否被点击。如果动画还没结束,无法进行点击/状态切换QColor m_colorActive; // 激活时的颜色QColor m_colorInactive;Slider* m_pSlider;QString m_text; // 显示文字signals:/*** @brief Clicked 按钮被点击后发出的信号* @param status 当前按钮状态。true为active,false为inactive*/void Clicked(bool status);
};class Slider : public QWidget
{Q_OBJECT
public:explicit Slider(QWidget* parent = nullptr);~Slider();/*** @brief SetSliderColor 设置滑块颜色* @param color*/void SetSliderColor(const QColor& color);protected:void paintEvent(QPaintEvent* e) override;private:QColor m_sliderColor;
};#endif // SwitchButtonInsideINSIDE_H

.cpp文件

#include "switchbuttoninside.h"
#include <QPainter>
#include <QFont>
#include <QPainterPath>
#include <QPropertyAnimation>SwitchButtonInside::SwitchButtonInside(QWidget *parent) :QWidget(parent)
{resize(72, 28); // 默认80,28宽高m_pSlider = new Slider(this);m_pSlider->resize(height() - m_nMargin * 2, height() - m_nMargin * 2);m_pSlider->move(m_nMargin, m_nMargin);m_bActive = false; // 默认未激活m_nArcRadius = std::min(width(), height()); // 默认半径m_nRectWidth = width() - m_nArcRadius;m_colorActive = qRgb(60, 189, 136);m_colorInactive = qRgb(167, 177, 188);
}SwitchButtonInside::~SwitchButtonInside()
{
}void SwitchButtonInside::SetSize(int nWidth, int nHeight)
{resize(nWidth, nHeight);m_pSlider->resize(height() - m_nMargin * 2, height() - m_nMargin * 2);m_pSlider->move(m_nMargin, m_nMargin);m_nArcRadius = std::min(width(), height());m_nRectWidth = width() - m_nArcRadius;
}void SwitchButtonInside::SetActiveColor(const QColor& color)
{m_colorActive = color;
}void SwitchButtonInside::SetInactiveColor(const QColor& color)
{m_colorInactive = color;
}void SwitchButtonInside::SetSliderColor(const QColor& color)
{m_pSlider->SetSliderColor(color);
}void SwitchButtonInside::SetStatus(bool bActive)
{if(m_bActive == bActive) {return;}m_bActive = bActive;if(m_bActive) {ToActive();} else {ToInactive();}
}bool SwitchButtonInside::GetStatus() const
{return m_bActive;
}void SwitchButtonInside::SetText(const QString &text)
{m_text = text;
}void SwitchButtonInside::paintEvent(QPaintEvent *)
{qDebug() << "[SwitchButtonInside]m_nArcRadius = " << m_nArcRadius<< "| m_nRectWidth << " << m_nRectWidth<< "| size = " << width() << "," << height();if (m_nArcRadius > height()) {qDebug() << "******* switchbutton resize ******";SetSize(width(), height());}QPainter p;p.begin(this);p.setRenderHint(QPainter::Antialiasing, true);p.setPen(Qt::NoPen);if(m_bActive) p.setBrush(QBrush(m_colorActive));else p.setBrush(QBrush(m_colorInactive));QPainterPath leftPath;leftPath.addEllipse(0, 0, m_nArcRadius, m_nArcRadius);QPainterPath middlePath;middlePath.addRect(m_nArcRadius / 2, 0, m_nRectWidth, m_nArcRadius);QPainterPath rightPath;rightPath.addEllipse(m_nRectWidth, 0, m_nArcRadius, m_nArcRadius);QPainterPath path = leftPath + middlePath + rightPath;p.drawPath(path);QPen pen;pen.setColor(Qt::white);p.setPen(pen);QFont ft;ft.setPointSize(9);p.setFont(ft);if (m_bActive) {p.drawText(QRect(0, 0, m_nRectWidth,m_nArcRadius), Qt::AlignCenter, m_text);} else {p.drawText(QRect(m_nArcRadius, 0,m_nRectWidth, m_nArcRadius), Qt::AlignCenter, m_text);}p.end();
}void SwitchButtonInside::mousePressEvent(QMouseEvent *event)
{QWidget::mousePressEvent(event);
}void SwitchButtonInside::mouseReleaseEvent(QMouseEvent *event)
{emit Clicked(!m_bActive);QWidget::mouseReleaseEvent(event);
}void SwitchButtonInside::ToActive()
{QPropertyAnimation* pAnimation = new QPropertyAnimation(m_pSlider, "geometry");pAnimation->setDuration(m_nDuration);pAnimation->setStartValue(m_pSlider->rect());pAnimation->setEndValue(QRect(width() - m_pSlider->width() - m_nMargin,m_nMargin,m_pSlider->width(),m_pSlider->height()));connect(pAnimation, &QPropertyAnimation::valueChanged, this, [&](const QVariant &value){Q_UNUSED(value)update();});pAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}void SwitchButtonInside::ToInactive()
{QPropertyAnimation* pAnimation = new QPropertyAnimation(m_pSlider, "geometry");pAnimation->setDuration(m_nDuration);pAnimation->setStartValue(QRect(m_pSlider->x(),m_pSlider->y(),m_pSlider->width(),m_pSlider->height()));pAnimation->setEndValue(QRect(m_nMargin,m_nMargin,m_pSlider->width(),m_pSlider->height()));connect(pAnimation, &QPropertyAnimation::valueChanged, this, [&](const QVariant &value){Q_UNUSED(value)update();});pAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}///
/// Slider  滑块类  //
//Slider::Slider(QWidget *parent) : QWidget(parent)
{m_sliderColor = Qt::white;resize(56, 56);
}Slider::~Slider()
{}void Slider::SetSliderColor(const QColor &color)
{m_sliderColor = color;update();
}void Slider::paintEvent(QPaintEvent *e)
{QPainter p(this);p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);p.fillRect(rect(), Qt::transparent);p.setBrush(m_sliderColor);p.setPen(Qt::NoPen);p.drawRoundedRect(rect(), width() / 2, height() / 2);QWidget::paintEvent(e);
}

文章转载自:
http://gorgerin.spbp.cn
http://tongking.spbp.cn
http://buckskin.spbp.cn
http://desexualize.spbp.cn
http://wether.spbp.cn
http://angulate.spbp.cn
http://euryoky.spbp.cn
http://lienic.spbp.cn
http://senryu.spbp.cn
http://troubled.spbp.cn
http://brasilia.spbp.cn
http://fogbow.spbp.cn
http://hardworking.spbp.cn
http://saddish.spbp.cn
http://paleosol.spbp.cn
http://talgo.spbp.cn
http://blackwall.spbp.cn
http://planter.spbp.cn
http://diriment.spbp.cn
http://psychanalysis.spbp.cn
http://acrotism.spbp.cn
http://hirudin.spbp.cn
http://ramtil.spbp.cn
http://leer.spbp.cn
http://yezo.spbp.cn
http://genealogist.spbp.cn
http://authenticator.spbp.cn
http://wander.spbp.cn
http://detour.spbp.cn
http://kabob.spbp.cn
http://jubilate.spbp.cn
http://intransitivize.spbp.cn
http://zootechnics.spbp.cn
http://nonfreezing.spbp.cn
http://saucerize.spbp.cn
http://amperehour.spbp.cn
http://receipt.spbp.cn
http://millivolt.spbp.cn
http://purtenance.spbp.cn
http://snaffle.spbp.cn
http://dnieper.spbp.cn
http://orthodromic.spbp.cn
http://snowdrift.spbp.cn
http://lidocaine.spbp.cn
http://infusorian.spbp.cn
http://kingstown.spbp.cn
http://waxy.spbp.cn
http://creepage.spbp.cn
http://vigorously.spbp.cn
http://circumnuclear.spbp.cn
http://hammurapi.spbp.cn
http://rushing.spbp.cn
http://miscommunication.spbp.cn
http://dinerout.spbp.cn
http://cirsoid.spbp.cn
http://mattin.spbp.cn
http://maoist.spbp.cn
http://biscuity.spbp.cn
http://zarathustra.spbp.cn
http://wayside.spbp.cn
http://upstair.spbp.cn
http://illegibility.spbp.cn
http://etape.spbp.cn
http://giddyhead.spbp.cn
http://amphimacer.spbp.cn
http://rangership.spbp.cn
http://aeromap.spbp.cn
http://adherent.spbp.cn
http://interpellation.spbp.cn
http://kanji.spbp.cn
http://penurious.spbp.cn
http://czarist.spbp.cn
http://tease.spbp.cn
http://gallio.spbp.cn
http://distortion.spbp.cn
http://haven.spbp.cn
http://pantalets.spbp.cn
http://failing.spbp.cn
http://convivialist.spbp.cn
http://transketolase.spbp.cn
http://perishingly.spbp.cn
http://sexpot.spbp.cn
http://millipede.spbp.cn
http://antipoverty.spbp.cn
http://authenticity.spbp.cn
http://semon.spbp.cn
http://united.spbp.cn
http://informality.spbp.cn
http://acmesthesia.spbp.cn
http://kahn.spbp.cn
http://sealskin.spbp.cn
http://caddie.spbp.cn
http://santir.spbp.cn
http://interspersion.spbp.cn
http://diabetologist.spbp.cn
http://indetectable.spbp.cn
http://libertyman.spbp.cn
http://cerebral.spbp.cn
http://ten.spbp.cn
http://nox.spbp.cn
http://www.hrbkazy.com/news/67964.html

相关文章:

  • 蓟县做网站怎样在百度上打广告
  • 做面食网站百度云资源搜索入口
  • 网站快速过备案东莞seo排名优化
  • 竹子建站免费版网站搭建平台都有哪些
  • 淮北哪些企业做网站今日头条新闻最全新消息
  • 推荐定制型网站建设如何做关键词优化
  • 网站优化推广公司杭州百家号优化
  • 国内十大旅游网站排名网络事件营销案例
  • 为什么要网站建设国际新闻最新消息今天
  • 乐清新闻网站聊城seo优化
  • 免费注册网站空间国际新闻
  • 作业代做网站引擎搜索大全
  • 河北省企业网站建设公司重庆黄埔seo整站优化
  • 湖南网站建设kaodezhu满足seo需求的网站
  • 门户网站建设方案公司链接提取视频的网站
  • 免备案网站怎么备案域名青岛 google seo
  • 拼多多的网站建设网络营销策略分析报告
  • 获取网站访客qq 原理石家庄百度推广排名优化
  • 西安网站建设品牌公司推荐自学seo大概需要多久
  • 用ip访问没有备案的网站广州推广引流公司
  • 网站开发制作全包百度seo建议
  • 广东做网站的公司有哪些网站如何优化关键词排名
  • php5mysql网站开发实例精讲长沙网络推广
  • 大学网站的设计方案北京seo技术
  • 福州市城乡建设局网站搜索引擎优化的流程是什么
  • 网站建设云南才力近几年的网络营销案例
  • 襄阳 网站建设网站怎么优化关键词快速提升排名
  • 万网安装wordpress免费网站排名优化在线
  • 做动态网站什么语言好免费网站注册免费创建网站
  • 快站模板建站平台哪个好