forked from DFRobot/Mindplus-Desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionAreaWidget.cpp
More file actions
89 lines (78 loc) · 1.56 KB
/
FunctionAreaWidget.cpp
File metadata and controls
89 lines (78 loc) · 1.56 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "FunctionAreaWidget.h"
#include <QMouseEvent>
#include <QDebug>
#include <QPen>
#include <QPainter>
FunctionAreaWidget::FunctionAreaWidget(QWidget *parent)
: QWidget(parent)
, hover_(false)
, fgImage_()
, name_("")
{
setupUi(this);
this->initSetting();
}
void FunctionAreaWidget::addData(const QPixmap &foreground, const QString &name)
{
fgImage_ = foreground;
name_ = name;
labelName->setText(name_);
labelName->setScaledContents(false);
labelImage->setPixmap(fgImage_);
}
void FunctionAreaWidget::setImage(const QPixmap &image)
{
labelImage->setPixmap(image);
}
void FunctionAreaWidget::setName(const QString &name)
{
labelName->setText(name);
}
void FunctionAreaWidget::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type())
{
case QEvent::LanguageChange:
retranslateUi(this);
break;
default:
break;
}
}
void FunctionAreaWidget::paintEvent(QPaintEvent *event)
{
if(hover_)
{
QPainter paint(this);
paint.setPen(QPen(QColor(51,51,51)));
paint.setBrush(QBrush(QColor(51,51,51)));
paint.drawRect(this->rect());
}
else
{
QWidget::paintEvent(event);
}
}
void FunctionAreaWidget::mousePressEvent(QMouseEvent *event)
{
Q_UNUSED(event);
//变颜色加入对事件的响应
hover_ = false;
update();
emit signalClick();
}
void FunctionAreaWidget::enterEvent(QEvent *)
{
hover_ = true;
update();
}
void FunctionAreaWidget::leaveEvent(QEvent *)
{
hover_ = false;
update();
}
void FunctionAreaWidget::initSetting()
{
this->setMouseTracking(true);
}