参考一 https://zhuanlan.zhihu.com/p/33874223
参考二 https://www.cnblogs.com/lomper/p/4249575.html
代码
void MainWindow::mouseMoveEvent(QMouseEvent *event) {
//获得相对于屏幕的坐标
QPoint sPoint1 = event->globalPos();
qDebug() << "相对于屏幕坐标1:" << "(" << sPoint1.rx() << "," << sPoint1.ry() << ")";
//获得相对于屏幕的坐标
QPoint sPoint2 = QCursor::pos();
qDebug() << "相对于屏幕坐标2:" << "(" << sPoint2.rx() << "," << sPoint2.ry() << ")";
//获得相对于窗口的坐标
QPoint windowPoint = this->mapFromGlobal(sPoint2);
qDebug() << "相对于窗口坐标:" << "(" << windowPoint.rx() << "," << windowPoint.ry() << ")";
//获得相对于控件的坐标
QPoint widgetPoint = ui->label->mapFromGlobal(sPoint1);
qDebug() << "相对于控件坐标:" << "(" << widgetPoint.rx() << "," << widgetPoint.ry() << ")";
}