此时窗口的移动则需要重写鼠标的移动事件来解决。
这里需要定义两个,一个是鼠标按下,一个是鼠标移动。
void Title_Widget::mousePressEvent(QMouseEvent *event)//窗口移动事件
{
if(event->button()==Qt::LeftButton)
{
dragPosition=event->globalPos()-frameGeometry().topLeft();//鼠标位置减去左上角的左边
event->accept();
}
}
void Title_Widget::mouseMoveEvent(QMouseEvent *event)//窗口移动事件
{
if(event->buttons()&Qt::LeftButton)
{
move(event->globalPos()-dragPosition);//鼠标位置减去按下点的坐标
event->accept();
}
}
这里的Title_Widget就是你的窗口,dragPosition是自己定义的一个点,QPoint类。当然,移动窗口的方法有很多,这只是一种而已。
转载于:https://my.oschina.net/u/2505464/blog/542357