jingweimo的个人博客分享 http://blog.sciencenet.cn/u/jingweimo

博文

Create flashing LED indicators with QtSvgRenderer

已有 1428 次阅读 2019-2-22 01:54 |系统分类:科研笔记

void QLed::paintEvent(QPaintEvent *)

{
    QString ledShapeAndColor;
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing, true);

    ledShapeAndColor=shapes[m_shape];

    if(m_value)
        ledShapeAndColor.append(colors[m_onColor]);
    else
        ledShapeAndColor.append(colors[m_offColor]);
    
    render = new QtSvgRenderer();
    renderer->load(ledShapeAndColor);
    renderer->render(&painter);
}


MainWindow::MainWindow(QWidget *parent) :

    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    qDebug()<<"MainWindow.";

    ui->led1->setShape(SQUARE);
    ui->led1->setOnColor(GREEN);
    ui->led2->setShape(CIRCLE);
    ui->led2->setOnColor(RED);

    led_status = TRUE;

    timer.setInterval(100);
    timer.start();
    connect(&timer, SIGNAL(timeout()), this, SLOT(timeHandler()), Qt::DirectConnection);
}

void MainWindow::timeHandler()
{
    //qDebug()<<"timeHandler()";
    if(led_status)
    {
        ui->led1->setValue(TRUE);
        ui->led2->setValue(TRUE);
        led_status = FALSE;
    }
    else
    {
        ui->led1->setValue(FALSE);
        ui->led2->setValue(FALSE);
        led_status = TRUE;
    }
}


1.png

References:

https://stackoverflow.com/questions/39592363/pulse-led-on-button-toggle-in-qt

https://stackoverflow.com/questions/8551690/how-to-render-a-scaled-svg-to-a-qimage

https://doc.qt.io/qt-5/qsvgrenderer.html#details




https://blog.sciencenet.cn/blog-578676-1163484.html

上一篇:What and where are the stack and heap
下一篇:[转载]Serial Communication with an Arduino using C++ on Windows
收藏 IP: 35.10.57.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-11-30 09:41

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部