forked from Blackmamba-xuan/QtQQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwechat.cpp
76 lines (64 loc) · 1.65 KB
/
wechat.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
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
#include "wechat.h"
#include "ui_wechat.h"
Wechat::Wechat(QWidget *parent) :
QWidget(parent),
ui(new Ui::Wechat)
{
ui->setupUi(this);
setWindowFlags(Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
ui->label_2->installEventFilter(this);
ui->label_3->installEventFilter(this);
}
Wechat::~Wechat()
{
delete ui;
}
void Wechat::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton)
{
this->setMouseTracking(true);
mouse_press = true;
//鼠标相对于窗体的位置(或者使用event->globalPos() - this->pos())
move_point = event->pos();
qDebug()<<"移动1";
qDebug()<<event->source();
}
}
void Wechat::mouseReleaseEvent(QMouseEvent *event)
{
//设置鼠标为未被按下
mouse_press = false;
}
void Wechat::mouseMoveEvent(QMouseEvent *event)
{
//若鼠标左键被按下
// qDebug()<<"mouse_press="<<event->globalPos();
if(mouse_press)
{
//鼠标相对于屏幕的位置
QPoint move_pos = event->globalPos();
//移动主窗体位置
this->move(move_pos - move_point);
}
}
bool Wechat::eventFilter(QObject *object, QEvent *e)
{
if(e->type()==QEvent::MouseButtonPress&&object==ui->label_3)
{
close();
}
else if(e->type()==QEvent::MouseButtonPress&&object==ui->label_2){
showMinimized();
qDebug()<<"最小化";
qDebug()<<mouse_press;
}
return false;
}
void Wechat::showEvent(QShowEvent *event)
{
qDebug()<<"出现了";
mouse_press=false;
qDebug()<<mouse_press;
}