QWidget* widget; QPoint globalPos = widget->mapToGlobal(QPoint(0, 0)); qDebug() << "Global position: " << globalPos;
QWidget* widget; QRect globalRect = widget->mapToGlobal(widget->rect()); qDebug() << "Global rectangle: " << globalRect;
QWidget* parentWidget; QPoint cursorPos = QCursor::pos(); QPoint parentPos = parentWidget->mapToGlobal(QPoint(0, 0)); QPoint menuPos = cursorPos - parentPos; QMenu menu; menu.exec(parentWidget->mapToGlobal(menuPos));This code snippet positions a pop-up menu at the position of the mouse cursor relative to the parent widget. These examples use the Qt library package, which is a popular cross-platform application and UI framework for C++.