不用ClipCursor(),直接上跨平台代码:
void MyMainWindow::leaveEvent(QEvent * event)
{
// Get the window geometry & cursor position
const QRect & rect = geometry();
QPoint position = QCursor::pos();
// Check the bounds
qint32 x = qBound(rect.left(), position.x(), rect.right());
qint32 y = qBound(rect.top(), position.y(), rect.bottom());
// Adjust the cursor
if (x != position.x() || y != position.y())
QCursor::setPos(x, y);
event->accept();
QMainWindow::leaveEvent(event);
}