|
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;
}
}
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
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-30 09:41
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社