private:
bool m_moving=false; //表示窗口是否在鼠标操作下移动
QPoint m_lastPos; //上一次的鼠标位置
void DlgLogin::mousePressEvent (QMouseEvent *event)
{
//鼠标按键被按下
if(event->button() == Qt::LeftButton)
{
m_moving = true;
m_lastPos = event->globalPos() - pos(); / /记录下鼠标相对于窗口的位置
}
return QDialog::mousePressEvent(event);
}
void DlgLogin::mouseMoveEvent(QMouseEvent *event)
{
//鼠标按下左键移动
if (m_moving && (event->buttons() && Qt::LeftButton)
&& (event->globalPos() - m_lastPos).manhattanLength() >
QApplication::startDragDistance())
{
move(event->globalPos() - m_lastPos); //横纵向移动一定的距离
m_lastPos = event->globalPos() - pos();//再一次记录坐标位置
}
return QDialog::mouseMoveEvent(event);
}
void DlgLogin::mouseReleaseEvent(QMouseEvent *event)
{
//鼠标按键释放
m_moving = false; //停止移动
}
01-06
336
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-10