-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlabel.cpp
More file actions
55 lines (49 loc) · 1.07 KB
/
label.cpp
File metadata and controls
55 lines (49 loc) · 1.07 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
#include"Label.h"
#include<QMouseEvent>
#include<QPainter>
#include<QPalette>
#include "QSyntaxHighlighter"
Label::Label(QString str,QTextEdit *text,QWidget *parent):
QLabel(parent)
{
this->setText(str);
setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
this->setCursor(Qt::PointingHandCursor);
count=0;
press=false;
over=false;
textEdit = text;
}
void Label::mouseReleaseEvent(QMouseEvent*event)
{
press=false;
update();
}
void Label::enterEvent(QEvent*)
{
over=true;
update();
}
void Label::leaveEvent(QEvent*)
{
over=false;
update();
}
void Label::paintEvent(QPaintEvent*event)
{
QPainter paint(this);
paint.setPen(QPen(Qt::red,1));
if(over)
{
QString str = QString::number(times);
this->setToolTip(str);
if(over)
highlighter = new MySyntaxHighlighter(words,textEdit->document());
paint.drawLine(5,this->height()-1,this->width()-5,this->height()-1);//绘制下划线
}
else
{
paint.setPen(Qt::NoPen);//当鼠标移开下划线
}
QLabel::paintEvent(event);
}