QPoint globalPoint = QCursor::pos(); // get global cursor position QPoint localPoint = myWidget->mapFromGlobal(globalPoint); // convert to local coordinates
QMouseEvent* event; // assume we have a mouse event QPoint globalPoint = event->globalPos(); // get global mouse position QPoint localPoint = myWidget->mapFromGlobal(globalPoint); // convert to local coordinatesIn this example, we retrieve the global mouse position from the `QMouseEvent` object. We then convert this global point to local widget coordinates using `mapFromGlobal()`. Overall, `QWidget::mapFromGlobal` is a useful function for mapping global screen coordinates to local widget coordinates. This function is part of the Qt Widgets module.