QT无标题栏窗体移动

原文:原文地址:http://blog.csdn.net/sidyhe/article/details/11648707

//添加成员变量
bool	m_MousePressed;
QPoint	m_MousePos;
QPoint	m_WindowPos;
//重载处理函数
void mousePressEvent(QMouseEvent *);  
void mouseReleaseEvent(QMouseEvent *);  
void mouseMoveEvent(QMouseEvent *);  
//具体实现
void MyClass::mousePressEvent(QMouseEvent *lpEvent)
{
	__super::mousePressEvent(lpEvent);
	if (lpEvent->button() == Qt::LeftButton)
	{
		m_WindowPos = this->pos();
		m_MousePos = lpEvent->globalPos();
		this->m_MousePressed = true;
	}
}

void MyClass::mouseReleaseEvent(QMouseEvent *lpEvent)
{
	__super::mouseReleaseEvent(lpEvent);
	if (lpEvent->button() == Qt::LeftButton)
	{
		this->m_MousePressed = false;
	}
}

void MyClass::mouseMoveEvent(QMouseEvent *lpEvent)
{
	if (m_MousePressed)
	{
		this->move(m_WindowPos + (lpEvent->globalPos() - m_MousePos));
	}
}
//构造函数中设置无标题栏
	setWindowFlags( Qt::FramelessWindowHint 
		| Qt::WindowMinMaxButtonsHint);
//包含的头文件
#include   
#include   


你可能感兴趣的:(QT无标题栏窗体移动)