当前位置:网站首页>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;
边栏推荐
- excel表格中选中单元格出现十字带阴影的选中效果
- MySQL linked list data storage query sorting problem
- ros缺少xacro的包
- Gaode draws lines according to the track
- 程序员成长第六篇:如何选择公司?
- mysql 基本语句
- From the perspective of attack surface, see the practice of zero trust scheme of Xinchuang
- Native method merge word
- LVM operation
- How to Create a Nice Box and Whisker Plot in R
猜你喜欢
mmrotate旋转目标检测框架使用记录
可昇級合約的原理-DelegateCall
GGPUBR: HOW TO ADD ADJUSTED P-VALUES TO A MULTI-PANEL GGPLOT
tidb-dm报警DM_sync_process_exists_with_error排查
The computer screen is black for no reason, and the brightness cannot be adjusted.
TDSQL|就业难?腾讯云数据库微认证来帮你
Always report errors when connecting to MySQL database
ren域名有价值吗?值不值得投资?ren域名的应用范围有哪些?
CentOS8之mysql基本用法
Multi line display and single line display of tqdm
随机推荐
map集合赋值到数据库
【云原生】2.5 Kubernetes 核心实战(下)
制造业数字化转型和精益生产什么关系
How to Create a Beautiful Plots in R with Summary Statistics Labels
Order by injection
CTF record
Fabric.js 3个api设置画布宽高
Installation of ROS gazebo related packages
Esp32 stores the distribution network information +led displays the distribution network status + press the key to clear the distribution network information (source code attached)
数字化转型挂帅复产复工,线上线下全融合重建商业逻辑
How to Easily Create Barplots with Error Bars in R
The position of the first underline selected by the vant tabs component is abnormal
电脑无缘无故黑屏,无法调节亮度。
Precautions for scalable contract solution based on openzeppelin
Principe du contrat évolutif - delegatecall
对毕业季即将踏入职场的年轻人的一点建议
Pit of the start attribute of enumrate
PHP query distance according to longitude and latitude
php 根据经纬度查询距离
Eight sorting summaries