-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasewidget.cpp
84 lines (76 loc) · 2.45 KB
/
basewidget.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
77
78
79
80
81
82
83
84
#include "basewidget.h"
EButton::EButton(QWidget *parent) : QPushButton(parent)
{
setObjectName("Button");
setMouseTracking(true); //开启鼠标追踪
setFocusPolicy(Qt::StrongFocus);
m_propertyList<<"backColor"<<"text";
}
void EButton::mouseMoveEvent(QMouseEvent *event)
{
if (this->focusWidget() != this) return;
event->ignore();
if (event->buttons() & Qt::LeftButton){
move(event->globalPos() - dragPosition);
emit currentItemChanged(this);
}
}
void EButton::mousePressEvent(QMouseEvent *event)
{
event->ignore();
if (event->button() == Qt::LeftButton) //每当按下鼠标左键就记录一下位置
{
dragPosition = event->globalPos() - frameGeometry().topLeft(); //获得鼠标按键位置相对窗口左上面的位置
}
}
EText::EText(QWidget *parent) : QLabel(parent)
{
setObjectName("Text");
setMouseTracking(true); //开启鼠标追踪
setFocusPolicy(Qt::StrongFocus);
setStyleSheet("border: 1px solid black;");
m_propertyList<<"backColor"<<"text"<<"alignment";
}
void EText::mouseMoveEvent(QMouseEvent *event)
{
if (this->focusWidget() != this) return;
event->ignore();
if (event->buttons() & Qt::LeftButton){
move(event->globalPos() - dragPosition);
emit currentItemChanged(this);
}
}
void EText::mousePressEvent(QMouseEvent *event)
{
event->ignore();
if (event->button() == Qt::LeftButton) //每当按下鼠标左键就记录一下位置
{
dragPosition = event->globalPos() - frameGeometry().topLeft(); //获得鼠标按键位置相对窗口左上面的位置
}
}
EEdit::EEdit(QWidget *parent) :
QLineEdit(parent),
maxLen(30) //每个字符3个字节,30为10个字符大小
{
setObjectName("Edit");
setMouseTracking(true); //开启鼠标追踪
setFocusPolicy(Qt::StrongFocus);
m_propertyList<<"backColor"<<"text"<<"alignment"<<"maxLen";
}
void EEdit::mouseMoveEvent(QMouseEvent *event)
{
if (this->focusWidget() != this) return;
event->ignore();
if (event->buttons() & Qt::LeftButton){
move(event->globalPos() - dragPosition);
emit currentItemChanged(this);
}
}
void EEdit::mousePressEvent(QMouseEvent *event)
{
event->ignore();
if (event->button() == Qt::LeftButton) //每当按下鼠标左键就记录一下位置
{
dragPosition = event->globalPos() - frameGeometry().topLeft(); //获得鼠标按键位置相对窗口左上面的位置
}
}