当前位置:网站首页>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 Create a Beautiful Plots in R with Summary Statistics Labels
- easyExcel和lombok注解以及swagger常用注解
- HOW TO CREATE A BEAUTIFUL INTERACTIVE HEATMAP IN R
- C#多维数组的属性获取方法及操作注意
- CTF record
- 在连接mysql数据库的时候一直报错
- RPA advanced (II) uipath application practice
- 念念不忘,必有回响 | 悬镜诚邀您参与OpenSCA用户有奖调研
- 基于Hardhat和Openzeppelin开发可升级合约(二)
- Research on and off the Oracle chain
猜你喜欢

PowerBI中导出数据方法汇总
![[visual studio 2019] create MFC desktop program (install MFC development components | create MFC application | edit MFC application window | add click event for button | Modify button text | open appl](/img/6a/111da81436659c7502648907ec1367.jpg)
[visual studio 2019] create MFC desktop program (install MFC development components | create MFC application | edit MFC application window | add click event for button | Modify button text | open appl

The selected cells in Excel form have the selection effect of cross shading

Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting

PLC-Recorder快速监控多个PLC位的技巧

2022年4月17日五心红娘团队收获双份喜报

基于Hardhat和Openzeppelin开发可升级合约(二)

Solve the problem of data blank in the quick sliding page of the uniapp list

Pyqt5+opencv project practice: microcirculator pictures, video recording and manual comparison software (with source code)

ren域名有价值吗?值不值得投资?ren域名的应用范围有哪些?
随机推荐
2022年4月17日五心红娘团队收获双份喜报
vant tabs组件选中第一个下划线位置异常
HOW TO CREATE A BEAUTIFUL INTERACTIVE HEATMAP IN R
qt 仪表自定义控件
C file and folder operation
What week is a date obtained by QT
MySql存储过程游标遍历结果集
Esp32 audio frame esp-adf add key peripheral process code tracking
Three transparent LED displays that were "crowded" in 2022
deepTools对ChIP-seq数据可视化
ESP32 Arduino 引入LVGL 碰到的一些问题
[cloud native] 2.5 kubernetes core practice (Part 2)
PX4 Position_Control RC_Remoter引入
亚马逊云科技 Community Builder 申请窗口开启
BEAUTIFUL GGPLOT VENN DIAGRAM WITH R
Never forget, there will be echoes | hanging mirror sincerely invites you to participate in the opensca user award research
The position of the first underline selected by the vant tabs component is abnormal
Homer forecast motif
Tdsql | difficult employment? Tencent cloud database micro authentication to help you
Precautions for scalable contract solution based on openzeppelin