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

洛阳住房和城乡建设厅网站公司网页怎么制作

洛阳住房和城乡建设厅网站,公司网页怎么制作,android应用程序开发教程,cherry framework wordpress文章目录 0 引入1、带有标尺的温度/湿度计控件1.头文件2.核心代码 2、竖起来的温度/湿度计控件1.头文件2.实现 3、引用 0 引入 QT原生控件没有实现如仪表盘或者温度计的控件,只好自己实现,文章代码部分参考引用的文章。直接上图 图一 带有标尺的温度计…

文章目录

  • 0 引入
  • 1、带有标尺的温度/湿度计控件
    • 1.头文件
    • 2.核心代码
  • 2、竖起来的温度/湿度计控件
    • 1.头文件
    • 2.实现
  • 3、引用


在这里插入图片描述

0 引入

QT原生控件没有实现如仪表盘或者温度计的控件,只好自己实现,文章代码部分参考引用的文章。直接上图

图一 带有标尺的温度计、湿度带有标尺的温度计、湿度
图二 温度计、湿度

在这里插入图片描述
控件最核心的部分:在函数paintEvent绘制部分,如果需要动画效果还需要加一个QPropertyAnimation ,这是最主要的,剩下的细节根据需求增加减少即可。


1、带有标尺的温度/湿度计控件

因为只做数据显示用,所以只需要向控件传数据即可。
主要功能:1、可设置显示范围;
2、显示过程中加了动画效果;
3、背景色和前景色以及刻度尺颜色可变;
4、刻度尺间距可变,控件大小随着QWidget适应;

1.头文件

代码如下(示例):

protected:void paintEvent(QPaintEvent *);void drawBg(QPainter *painter);void drawProgress(QPainter *painter);void drawRulerTop(QPainter *painter);void drawRulerBottom(QPainter *painter);private:QPropertyAnimation *m_valueAnimation;double minValue;                //最小值double maxValue;                //最大值qreal value;                    //当前值int longStep;                   //长线条等分步长int shortStep;                  //短线条等分步长bool rulerTop;                  //刻度线在上面bool isAdd;                     //是否为增加,默认为的增加QColor bgColor;                 //背景颜色QColor lineColor;               //线条颜色QColor progressColor;           //进度颜色public:qreal getValue()               const;void setrulerTop(bool istop);   //设定刻度线再上还是在下,默认是在上void setValue(qreal v);void setRange(int minValue, int maxValue);void startAnimation();void updateValue(double value);void setBgColor(const QColor &bgColor);               //设置背景颜色void setLineColor(const QColor &lineColor);           //设置线条颜色void setProgressColor(const QColor &progressColor);   //设置进度颜色

2.核心代码

绘制部分参考引用2代码,感谢刘典武老师的无私开源,有需要的可去做定制。
代码如下:

void HumidityProgress::startAnimation()
{qreal startValue =  value;if(isAdd){m_valueAnimation->setKeyValueAt(0.5, value+0.5);m_valueAnimation->setKeyValueAt(1, value);m_valueAnimation->setStartValue(startValue-0.5);m_valueAnimation->start();}else{m_valueAnimation->setKeyValueAt(0.5, value-0.5);m_valueAnimation->setKeyValueAt(1, value);m_valueAnimation->setStartValue(startValue+0.5);m_valueAnimation->start();}}void HumidityProgress::paintEvent(QPaintEvent *)
{//绘制准备工作,启用反锯齿QPainter painter(this);painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);//按照绘制顺序drawBg(&painter);drawProgress(&painter);if (rulerTop) {drawRulerTop(&painter);} else {drawRulerBottom(&painter);}
}void HumidityProgress::drawBg(QPainter *painter)
{painter->save();painter->setPen(lineColor);painter->setBrush(bgColor);painter->drawRect(rect());painter->restore();
}void HumidityProgress::drawProgress(QPainter *painter)
{painter->save();painter->setPen(Qt::NoPen);painter->setBrush(progressColor);double length = width();double increment = length / (maxValue - minValue);double initX = (value - minValue) * increment;QRect rect(0, 0, initX, height());painter->drawRect(rect);painter->restore();
}void HumidityProgress::drawRulerTop(QPainter *painter)
{painter->save();painter->setPen(lineColor);double initX = 0;//绘制横向标尺上部分底部线double initTopY = 0;QPointF lineTopLeftPot = QPointF(initX, initTopY);QPointF lineTopRightPot = QPointF(width() - initX, initTopY);painter->drawLine(lineTopLeftPot, lineTopRightPot);//绘制上部分及下部分横向标尺刻度double length = width();//计算每一格移动多少double increment = length / (maxValue - minValue);//长线条短线条长度int longLineLen = 15;int shortLineLen = 10;//根据范围值绘制刻度值及刻度值 长线条需要移动10像素 短线条需要移动5像素for (int i = minValue; i <= maxValue; i = i + shortStep) {if (i % longStep == 0) {QPointF topPot = QPointF(initX, initTopY);QPointF bottomPot = QPointF(initX, initTopY + longLineLen);painter->drawLine(topPot, bottomPot);//第一个值和最后一个值不要绘制if (i == minValue || i == maxValue) {initX += increment * shortStep;continue;}QString strValue = QString("%1").arg((double)i, 0, 'f', 0);double textWidth = fontMetrics().width(strValue);double textHeight = fontMetrics().height();QPointF textPot = QPointF(initX - textWidth / 2, initTopY + textHeight + longLineLen);painter->drawText(textPot, strValue);} else {if (i % (longStep / 2) == 0) {shortLineLen = 10;} else {shortLineLen = 6;}QPointF topPot = QPointF(initX, initTopY);QPointF bottomPot = QPointF(initX, initTopY + shortLineLen);painter->drawLine(topPot, bottomPot);}initX += increment * shortStep;}painter->restore();
}

该处使用的url网络请求的数据。


2、竖起来的温度/湿度计控件

因为只做数据显示用,所以只需要向控件传数据即可。
控件是好看,但是大小不能改变,所以这里需要自己实现了,源码作者已经放上。

1.头文件

代码如下(示例):

#ifndef THERMOMETREDLG_H
#define THERMOMETREDLG_H#include <QWidget>
#include <QPropertyAnimation>
#include <QPainter>
#include <QTimer>class thermometreDlg : public QWidget
{Q_OBJECTQ_PROPERTY(qreal value READ getValue WRITE setValue)  //声明属性public:explicit thermometreDlg(QWidget *parent = nullptr);qreal getValue();void setValue(qreal value);void changeValue(qreal value);protected:void paintEvent(QPaintEvent *e);public slots:void startAnimation();signals:private:qreal m_value;qreal curValue;int m_width;QRectF m_rect;int maxValue, minValue;qreal m_radius;QPropertyAnimation *m_valueAnimation;void updateRect();};#endif // THERMOMETREDLG_H

2.实现

代码如下(示例):

#include "thermometredlg.h"
#include <QDebug>thermometreDlg::thermometreDlg(QWidget *parent) : QWidget(parent)
{m_width = 20;maxValue = 100;minValue = 0;m_radius = 1.05;m_value = 0;curValue = m_value;QTimer *at = new QTimer(this);at->start(1000);m_valueAnimation = new QPropertyAnimation(this, "value");m_valueAnimation->setDuration(1000);m_valueAnimation->setEasingCurve(QEasingCurve::OutCubic);m_valueAnimation->setLoopCount(1);connect(at, SIGNAL(timeout()), this, SLOT(startAnimation()));}void thermometreDlg::updateRect()
{m_rect.setX(0);m_rect.setY(20 - height()/2);m_rect.setWidth(m_width);m_rect.setHeight(height() - 40 - m_width* m_radius);
}void thermometreDlg::setValue(qreal value)
{m_value = value;update();
}void thermometreDlg::changeValue(qreal value)
{if(value > maxValue)value = maxValue;if(value < minValue)value = minValue;curValue = value;
}qreal thermometreDlg::getValue()
{return m_value;
}void thermometreDlg::paintEvent(QPaintEvent *e)
{updateRect();QPainter painter(this);QPen pen(Qt::black);painter.translate(this->width()/2, this->height()/2);  //坐标轴移动到中心点painter.setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing);  // 启用反锯齿painter.save();//绘制上方的柱状painter.fillRect(m_rect, QColor(168,200, 225));//绘制底部的圆QRectF tmpRect = QRectF(m_rect.bottomLeft(), QPointF(m_width, height()/2- m_width*m_radius));painter.fillRect(tmpRect, QColor(255, 0, 0));painter.setPen(Qt::NoPen);painter.setBrush(QColor(255, 0, 0));painter.drawEllipse(tmpRect.bottomLeft()+QPointF(tmpRect.width()/2, 0),m_width*m_radius, m_width*m_radius);painter.restore();//绘制刻度以及刻度值painter.save();painter.setPen(QColor(Qt::black));int nYCount = (maxValue - minValue)/10+1;qreal perHeight = (m_rect.height())/nYCount;for (int i=0; i<nYCount; ++i) {QPointF basePoint = m_rect.bottomLeft() - QPointF(0, perHeight/2) - QPointF(0, perHeight*i);//左侧大刻度painter.drawLine(basePoint, basePoint+QPointF(-10, 0));for (int j=1; j<10; ++j) {if(i == nYCount -1)continue;painter.drawLine(basePoint-QPointF(0, perHeight/10*j),basePoint-QPointF(5, perHeight/10*j));}painter.drawText(basePoint+QPointF(-28, 4), QString("%1").arg(minValue+i*10));//右侧大刻度basePoint = m_rect.bottomRight() - QPointF(0, perHeight/2) - QPointF(0, perHeight*i);painter.drawLine(basePoint, basePoint+QPointF(10, 0));for (int j=1; j<10; ++j) {if(i == nYCount -1)continue;painter.drawLine(basePoint-QPointF(0, perHeight/10*j),basePoint-QPointF(-5, perHeight/10*j));}}painter.restore();//根据值填充m_rectqreal h = (m_value-minValue)/(maxValue-minValue)*(m_rect.height()-perHeight);if(h<0)h = 0;if(h > m_rect.height())h = m_rect.height();painter.fillRect(m_rect.adjusted(0, m_rect.height()-h-perHeight/2-1 , 0, 0), QColor(255, 0, 0));QWidget::paintEvent(e);
}void thermometreDlg::startAnimation()
{qreal startValue = getValue();m_valueAnimation->setKeyValueAt(0, startValue-1);m_valueAnimation->setKeyValueAt(0.5, curValue+1);m_valueAnimation->setKeyValueAt(1, curValue);m_valueAnimation->setStartValue(startValue-2);m_valueAnimation->start();
}

3、引用

1、用qt实现一个温度计控件
2、Qt编写自定义控件2-进度条标尺
3、Qt动画框架:QPropertyAnimation(属性动画)



文章转载自:
http://protreptic.c7491.cn
http://cuirassier.c7491.cn
http://sandalwood.c7491.cn
http://cpu.c7491.cn
http://plateresque.c7491.cn
http://piave.c7491.cn
http://guttiferous.c7491.cn
http://washy.c7491.cn
http://zanu.c7491.cn
http://ferromagnesian.c7491.cn
http://codify.c7491.cn
http://vehemently.c7491.cn
http://voorskot.c7491.cn
http://unweary.c7491.cn
http://primus.c7491.cn
http://bedfellow.c7491.cn
http://reprove.c7491.cn
http://clarinet.c7491.cn
http://slatter.c7491.cn
http://manado.c7491.cn
http://ghostdom.c7491.cn
http://shoptalk.c7491.cn
http://geist.c7491.cn
http://tartness.c7491.cn
http://nurserymaid.c7491.cn
http://climbable.c7491.cn
http://or.c7491.cn
http://dichloride.c7491.cn
http://microheterogeneity.c7491.cn
http://endoarteritis.c7491.cn
http://neuroactive.c7491.cn
http://hieland.c7491.cn
http://fructuous.c7491.cn
http://indecisive.c7491.cn
http://sliding.c7491.cn
http://nourice.c7491.cn
http://heavyish.c7491.cn
http://thiol.c7491.cn
http://stop.c7491.cn
http://wheelbox.c7491.cn
http://cataclysm.c7491.cn
http://glycogenic.c7491.cn
http://australasia.c7491.cn
http://calliope.c7491.cn
http://recognizance.c7491.cn
http://obituary.c7491.cn
http://saliferous.c7491.cn
http://catlike.c7491.cn
http://technics.c7491.cn
http://theropod.c7491.cn
http://clamorous.c7491.cn
http://leadwork.c7491.cn
http://furculum.c7491.cn
http://daimon.c7491.cn
http://vestibule.c7491.cn
http://curability.c7491.cn
http://thrombosthenin.c7491.cn
http://oregonian.c7491.cn
http://subaerial.c7491.cn
http://graduation.c7491.cn
http://septenarius.c7491.cn
http://politeness.c7491.cn
http://cotentin.c7491.cn
http://clover.c7491.cn
http://initiating.c7491.cn
http://acosmist.c7491.cn
http://sourpuss.c7491.cn
http://counterjumper.c7491.cn
http://cajeput.c7491.cn
http://halfvolley.c7491.cn
http://distensibility.c7491.cn
http://undertaken.c7491.cn
http://toadflax.c7491.cn
http://arbitratorship.c7491.cn
http://chinook.c7491.cn
http://episcopize.c7491.cn
http://workaholic.c7491.cn
http://pastorship.c7491.cn
http://scouter.c7491.cn
http://noseguard.c7491.cn
http://asset.c7491.cn
http://multisense.c7491.cn
http://frieze.c7491.cn
http://adactylous.c7491.cn
http://ratheripe.c7491.cn
http://state.c7491.cn
http://electrobiology.c7491.cn
http://orthophoto.c7491.cn
http://onychia.c7491.cn
http://simuland.c7491.cn
http://obligee.c7491.cn
http://isthmectomy.c7491.cn
http://insectual.c7491.cn
http://lamellar.c7491.cn
http://thrombasthenia.c7491.cn
http://thermoset.c7491.cn
http://visceralization.c7491.cn
http://scarp.c7491.cn
http://littleneck.c7491.cn
http://alumnae.c7491.cn
http://www.zhongyajixie.com/news/73683.html

相关文章:

  • 外贸网站建设 东莞营销网站建设选择原则
  • 福州网站建设专业公司搜索seo引擎
  • 网站个人主页模板如何开通自己的网站
  • 甘肃建设厅网站官网网络营销推广方案策划与实施
  • 山东seo网站网络推广营销公司
  • 山东建设部网站域名注册1元
  • ps做网站效果新泰网站设计
  • 深圳做网站比较好的公司直通车关键词怎么优化
  • 沈阳网站建设哪家公司好搜索引擎推广的三种方式
  • 外贸企业建网站怎么样才能引流客人进店
  • 网站建立的重要性正规的关键词优化软件
  • 做搜狗pc网站推广一款app的营销方案
  • 玩具网站模板网络营销的理解
  • 做好门户网站建设网络平台怎么创建
  • 网络营销方案策划论文镇江网站关键字优化
  • 南宁网站建设 超薄网络正规职业技能培训机构
  • 云主机如何建网站影响关键词优化的因素
  • 沈阳定制网站方案seo软件哪个好
  • 容桂做网站各大搜索引擎提交入口
  • 深圳商城网站设计费用站长之家工具查询
  • 建立什么样的网站好深圳龙岗区疫情最新消息
  • seo 网站文章一般要多少字推广竞价托管费用
  • 个人备案网站放什么资料官方进一步优化
  • 福州企业网站制作搜索关键词优化服务
  • 网站开启速度班级优化大师
  • 潍坊做网站的沈阳百度seo关键词排名优化软件
  • 做网站卖什么产品利润高如何使用免费b站推广网站
  • 湖北省住房与建设厅网站群排名优化软件
  • 南京网站开发南京乐识赞最新经济新闻
  • 网站开发程序员 工资应用商店搜索优化