当前位置:网站首页>qt 仪表自定义控件
qt 仪表自定义控件
2022-07-02 09:41:00 【东方忘忧】

源码
qwidget(paintevent事件实现)废话不多说实现逻辑如下:
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("微软雅黑",12,QFont::Bold,false));
p.drawText(-50,40,100,40,Qt::AlignHCenter,val);
//圆弧
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;
边栏推荐
- 制造业数字化转型和精益生产什么关系
- Principle of scalable contract delegatecall
- Digital transformation takes the lead to resume production and work, and online and offline full integration rebuilds business logic
- QT获取某个日期是第几周
- The position of the first underline selected by the vant tabs component is abnormal
- The computer screen is black for no reason, and the brightness cannot be adjusted.
- Installation of ROS gazebo related packages
- Order by注入
- The difference between SQL left join main table restrictions written after on and where
- Homer预测motif
猜你喜欢

mysql链表数据存储查询排序问题

Multi line display and single line display of tqdm

The computer screen is black for no reason, and the brightness cannot be adjusted.

tidb-dm报警DM_sync_process_exists_with_error排查

2022年遭“挤爆”的三款透明LED显示屏

Mmrotate rotation target detection framework usage record

Redis exceeds the maximum memory error oom command not allowed when used memory & gt; ' maxmemory'

Develop scalable contracts based on hardhat and openzeppelin (II)

预言机链上链下调研

A white hole formed by antineutrons produced by particle accelerators
随机推荐
Bedtools tutorial
Never forget, there will be echoes | hanging mirror sincerely invites you to participate in the opensca user award research
A sharp tool for exposing data inconsistencies -- a real-time verification system
Redis exceeds the maximum memory error oom command not allowed when used memory & gt; ' maxmemory'
Cluster Analysis in R Simplified and Enhanced
基于Hardhat和Openzeppelin开发可升级合约(二)
Rest (XOR) position and thinking
tqdm的多行显示与单行显示
Astparser parsing class files with enum enumeration methods
Supermarket (heap overload
VS2019代码中包含中文内容导致的编译错误和打印输出乱码问题
ESP32存储配网信息+LED显示配网状态+按键清除配网信息(附源码)
Seriation in R: How to Optimally Order Objects in a Data Matrice
在连接mysql数据库的时候一直报错
ctf 记录
Is it safe to open a stock account through the QR code of the securities manager? Or is it safe to open an account in a securities company?
QT获取某个日期是第几周
CentOS8之mysql基本用法
Tiktok overseas tiktok: finalizing the final data security agreement with Biden government
How to Create a Nice Box and Whisker Plot in R