I'm making a virtual environment with Qt's OpenGL widget and I want to be able to "trap" the mouse in the center of the widget. My idea was to do this:

Qt Code:
  1. QPointF widgetPos = mapToGlobal(pos());
  2. QCursor::setPos(widgetPos.x() + width()/2, widgetPos.y() + height()/2);
To copy to clipboard, switch view to plain text mode 
However, widgetPos doesn't contain the top left corner of the screen as I would have hoped, so the cursor gets locked at the wrong position. Am I going about this the wrong way?