-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainapp.cpp
More file actions
48 lines (42 loc) · 926 Bytes
/
mainapp.cpp
File metadata and controls
48 lines (42 loc) · 926 Bytes
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
#include "mainapp.h"
#include "ui_mainapp.h"
MainApp::MainApp(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainApp)
{
ui->setupUi(this);
pressed = false;
ui->label->installEventFilter(this);
}
MainApp::~MainApp()
{
delete ui;
}
void MainApp::mousePressEvent(QMouseEvent *event)
{
//current = event->pos();
}
void MainApp::mouseMoveEvent(QMouseEvent *event)
{
if(pressed)
{
this->move(mapToParent(event->pos() - current));
}
}
bool MainApp::eventFilter(QObject *object, QEvent *event)
{
if (object == ui->label && event->type() == QEvent::MouseButtonPress)
{
current.setX(ui->label->x()+50);
current.setY(ui->label->y()+70);
pressed = true;
return true;
}
if (object == ui->label && event->type() == QEvent::MouseButtonRelease)
{
pressed = false;
return true;
}
else
return false;
}