ZIPQT自定义指示灯(可闪烁、可移动) 12.6KB

u012959478需要积分:5(1积分=1元)

资源文件列表:

pilot_lamp_Demo.zip 大约有15个文件
  1. pilot_lamp_Demo/
  2. pilot_lamp_Demo/imagelamp.cpp 1.43KB
  3. pilot_lamp_Demo/imagelamp.h 454B
  4. pilot_lamp_Demo/lamp.cpp 1.96KB
  5. pilot_lamp_Demo/lamp.h 1.2KB
  6. pilot_lamp_Demo/main.cpp 183B
  7. pilot_lamp_Demo/mainwindow.cpp 798B
  8. pilot_lamp_Demo/mainwindow.h 231B
  9. pilot_lamp_Demo/pilot_lamp_Demo.pro 792B
  10. pilot_lamp_Demo/res/
  11. pilot_lamp_Demo/res/lampOFF.png 3.24KB
  12. pilot_lamp_Demo/res/lampON.png 3.37KB
  13. pilot_lamp_Demo/roundlamp.cpp 2.2KB
  14. pilot_lamp_Demo/roundlamp.h 554B
  15. pilot_lamp_Demo/rs.qrc 119B

资源介绍:

QT实现指示灯控件。一般有2种形式:1、使用QPixmap绘制指示灯;2、在paintEvent中使用QPainter来绘制。本示例对这两种形式做了封装,实现了两种不同的指示灯。都可闪烁、可移动。
#include "roundlamp.h" RoundLamp::RoundLamp(QWidget *parent) : Lamp(parent) { setFixedSize(50,50); m_onColor=QColor("green"); m_offColor=QColor(125,125,125); setTickTime(m_tickTime); } RoundLamp::~RoundLamp() { } void RoundLamp::upFrameOut(QPainter *p,int r) { p->save(); QLinearGradient gradient(0,-r,0,r); gradient.setColorAt(1,QColor(166,166,166)); gradient.setColorAt(0,QColor(255,255,255)); gradient.setSpread(QGradient::PadSpread); p->setBrush(gradient); p->drawEllipse(-r,-r,2*r,2*r); p->restore(); update(); } void RoundLamp::upFrameIn(QPainter *p, int r) { p->save(); QLinearGradient gradient(0,-r,0,r); gradient.setColorAt(0,QColor(166,166,166)); gradient.setColorAt(1,QColor(255,255,255)); gradient.setSpread(QGradient::PadSpread); p->setBrush(gradient); p->drawEllipse(-r,-r,2*r,2*r); p->restore(); update(); } void RoundLamp::upLampColor(QPainter *p,int r) { p->save(); if(m_state) { if(m_canTick) { if(m_tickState) p->setBrush(m_onColor); else p->setBrush(m_offColor); } else p->setBrush(m_onColor); } else p->setBrush(m_offColor); p->drawEllipse(-r,-r,2*r,2*r); p->restore(); update(); } void RoundLamp::setTickTime(int tickTime) { m_tickTimer.setInterval(tickTime); connect(&m_tickTimer,&QTimer::timeout,this,[this]{ if(m_tickState) m_tickState=false; else m_tickState=true; }); } void RoundLamp::paintEvent(QPaintEvent *event) { Q_UNUSED(event); int width=this->width(); int height=this->height(); int side=qMin(width,height); QPainter p(this); p.translate(width/2,height/2); p.scale(side/200.0,side/200.0); p.setPen(Qt::NoPen); if(m_canTick&&(!m_tickTimer.isActive())) m_tickTimer.start(m_tickTime); else if(!m_canTick&&m_tickTimer.isActive()) m_tickTimer.stop(); upFrameOut(&p,99); upFrameIn(&p,90); upLampColor(&p,80); upText(&p); } void RoundLamp::setOnColor(QColor onColor) { m_onColor = onColor; update(); }
100+评论
captcha
    类型标题大小时间
    ZIP完成MySoothe应用的界面设计1.59MB9月前
    ZIP4.bd-stm32f103-exti.zip6.5MB9月前
    ZIP1-7代码全景.zip1.22MB9月前
    ZIP数电—设计一多人表决器.zip11.42MB9月前
    ZIP高级语言程序设计(C语言)-上课教学PPT+课程设计PPT+作业答案5.68MB9月前
    ZIPC语言+数据结构学期课程设计《员工管理系统》6.35KB9月前
    ZIPJDK-API 中文版文档34.72MB9月前
    ZIPGodot小游戏(1.0)26.1MB9月前