mainwindow.h中:
private:
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
private:
QPoint windowPos,mousePos,dPos;
mainwindow.cpp中:
void MainWindow::mousePressEvent(QMouseEvent *event)
{
this->windowPos = this->pos();
this->mousePos = event->globalPos();
this->dPos = mousePos - windowPos;
}
void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
this->move(event->globalPos() - this->dPos);
}