You can use QCursor in a mouseMoveEvent(), and check the location of the mouse pointer, and move it back if it comes to the edge of your widget.
A better method probably would be to use QHoverEvent, where you can react to a HoverLeave event, to place the cursor back on the widget.