/
warning.cpp
46 lines (39 loc) · 909 Bytes
/
warning.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "warning.h"
Warning::Warning(QString warning, QGraphicsItem *parent)
: QGraphicsTextItem(parent)
{
this->warning = warning;
state = true;
timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(changeState()));
timer->start(500);
}
Warning::~Warning()
{
this->deleteLater();
}
QRectF Warning::boundingRect() const
{
return QRectF(QPointF(100,200),QSize(400,200));
}
void Warning::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
if(state) {
painter->setFont(QFont("Time New Roman",20));
painter->setPen(QPen(Qt::red,3));
painter->drawText(QPointF(180,300),QString(warning));
}
}
void Warning::changeState()
{
if(state) {
state = false;
update();
}
else {
state = true;
update();
}
}