拖动控件,即拖动窗口

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
virtual voidmousePressEvent(QMouseEvent* e);    // 鼠标的单击事件

virtual voidmouseMoveEvent(QMouseEvent* e); // 鼠标的移动事件

virtualvoid mouseReleaseEvent(QMouseEvent* e); // 鼠标的单击释放事件

bool m_bIsWindowMoveable;

voidClassName::mousePressEvent(QMouseEvent* e)
{
if(e->button() == Qt::LeftButton)
{
m_bIsWindowMoveable = true;
}
}

void ClassName:mouseMoveEvent(QMouseEvent*e)
{
if(m_ bIsWindowMoveable)
{
move(e->globalPos());
}
}

voidClassName::mouseReleaseEvent(QMouseEvent* e)
{
m_bIsWindowMoveable = false;
}