void MainWindow::mousePressEvent(QMouseEvent* event)
{
if(event->button()==Qt::LeftButton)
{
drag=true;
pos=event->pos();
}
}
void MainWindow::mouseMoveEvent(QMouseEvent* event)
{
if(this->drag)
{
QPoint npos = event->pos()-this->pos;
Qpoint nposs=Qpoint(this->x()+npos.x(),this->y()+npos.y());
this->move(nposs);
}
}
void MainWindow::mouseReleaseEvent(QMouseEvent* event)
{
if(event->button()==Qt::LeftButton)
{
drag=false;
}
}
drag类成员变量
pos类成员变量