当前位置:网站首页>QT meter custom control
QT meter custom control
2022-07-02 11:48:00 【Oriental forgetfulness】
Source code
qwidget(paintevent Event implementation ) No more nonsense. The implementation logic is as follows :
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
p.translate(width() / 2, height() / 2);
int anglevalue = 0;
QPen pen;
pen.setColor(QColor("#646464A0"));
pen.setWidth(4);
p.setPen(pen);
p.drawEllipse(QPoint(0,0),104,104);
p.setPen(QColor("#636363"));
p.drawEllipse(QPoint(0,0),105,105);
p.setPen(QColor("#636363"));
p.setBrush(Qt::black);
p.drawEllipse(QPoint(0,0),100,100);
p.setPen(QColor("#636363"));
QLinearGradient lineargradient(0,-100,0,100);
lineargradient.setColorAt(0,QColor("#FF005600"));
lineargradient.setColorAt(0.5,QColor("#FF005600"));
lineargradient.setColorAt(1,QColor("#00005600"));
lineargradient.setSpread(QGradient::PadSpread);
QBrush brush = QBrush(lineargradient);
p.setBrush(brush);
p.drawEllipse(QPoint(0,0),100,100);
p.setPen(Qt::red);
for (int i = 0; i < BigScale; ++i) {
if (anglevalue < 60 || anglevalue > 120)
{
p.drawLine(85,0,100,0);
}
double angle = 360.00/BigScale;
p.rotate(angle);
anglevalue = anglevalue + angle;
}
anglevalue = 0;
p.setPen(Qt::yellow);
for (int i = 0; i < ModleScale; ++i) {
if (anglevalue <= 60 || anglevalue >= 120)
{
if (i % 3 != 0)
p.drawLine(90,0,100,0);
}
double angle = 360.00/ModleScale;
p.rotate(angle);
anglevalue = anglevalue + angle;
}
anglevalue = 0;
p.setPen(Qt::white);
for (int i = 0; i < SmallScale; ++i) {
if (anglevalue < 60 || anglevalue > 120)
{
if (i % 5 != 0)
p.drawLine(95,0,100,0);
}
double angle = 360.00/SmallScale;
p.rotate(angle);
anglevalue = anglevalue + angle;
}
anglevalue = 0;
p.setPen(Qt::white);
QStringList list;
list<<"180"<<"210"<<"240"<<"270"<<"300"<<"330"<<"360"<<"30"<<"60"<<"90"<<"120"<<"150";
for (int i = 0; i < ModleScale; ++i) {
if (anglevalue >= 210 || anglevalue <= 150)
{
p.drawText(QRect(-8,-85,16,16),Qt::AlignHCenter,list[i]);
}
double angle = 360.00/ModleScale;
p.rotate(angle);
anglevalue = anglevalue + angle;
}
p.save();
pen.setColor(Qt::gray);
p.setPen(pen);
QPoint points[3];
points[0] = QPoint(-3,0);
points[1] = QPoint(3,0);
points[2] = QPoint(0,100);
if (m_xangle < 30)
m_xangle = 330;
else if(m_xangle>330)
m_xangle = 30;
p.rotate(m_xangle);
p.drawConvexPolygon(points,3);
p.restore();
QString val = QString("%1km/h").arg(m_xangle);
pen.setColor(Qt::white);
p.setPen(pen);
p.setFont(QFont(" Microsoft YaHei ",12,QFont::Bold,false));
p.drawText(-50,40,100,40,Qt::AlignHCenter,val);
// arc
QConicalGradient conicalGradient(0,0,242);
conicalGradient.setColorAt(0,QColor("#FFFF0000"));
conicalGradient.setColorAt(0.5,QColor("#7DFF0000"));
conicalGradient.setColorAt(0.75,QColor("#FF005600"));
conicalGradient.setColorAt(1,QColor("#007D5600"));
conicalGradient.setSpread(QGradient::PadSpread);
pen = QPen(QBrush(conicalGradient),5);
p.setPen(pen);
QRect arcRect = QRect(-110,-110,220,220);
double startAngle = 240 * 16;
double spanAngle = -(m_xangle - 30) * 16;
p.drawArc(arcRect,startAngle,spanAngle);
qDebug()<<m_xangle;
边栏推荐
- How to Add P-Values onto Horizontal GGPLOTS
- Is the stock account given by qiniu business school safe? Can I open an account?
- Native method merge word
- What is the relationship between digital transformation of manufacturing industry and lean production
- 原生方法合并word
- 基于Hardhat和Openzeppelin开发可升级合约(一)
- Astparser parsing class files with enum enumeration methods
- Installation of ROS gazebo related packages
- How to Easily Create Barplots with Error Bars in R
- On April 17, 2022, the five heart matchmaker team received double good news
猜你喜欢
ESP32音频框架 ESP-ADF 添加按键外设流程代码跟踪
map集合赋值到数据库
Map set assignment to database
PLC-Recorder快速监控多个PLC位的技巧
FLESH-DECT(MedIA 2021)——一个material decomposition的观点
八大排序汇总
Power Spectral Density Estimates Using FFT---MATLAB
Pyqt5+opencv project practice: microcirculator pictures, video recording and manual comparison software (with source code)
解决uniapp列表快速滑动页面数据空白问题
II Stm32f407 chip GPIO programming, register operation, library function operation and bit segment operation
随机推荐
GGPlot Examples Best Reference
ros缺少xacro的包
Precautions for scalable contract solution based on openzeppelin
C#多维数组的属性获取方法及操作注意
Power Spectral Density Estimates Using FFT---MATLAB
mysql 基本语句
PYQT5+openCV项目实战:微循环仪图片、视频记录和人工对比软件(附源码)
Astparser parsing class files with enum enumeration methods
预言机链上链下调研
Tdsql | difficult employment? Tencent cloud database micro authentication to help you
FLESH-DECT(MedIA 2021)——一个material decomposition的观点
Tiktok overseas tiktok: finalizing the final data security agreement with Biden government
【多线程】主线程等待子线程执行完毕在执行并获取执行结果的方式记录(有注解代码无坑)
Native method merge word
2022年4月17日五心红娘团队收获双份喜报
Research on and off the Oracle chain
On April 17, 2022, the five heart matchmaker team received double good news
接口调试工具概论
PX4 Position_Control RC_Remoter引入
How to Easily Create Barplots with Error Bars in R