void Widget::on_pushButton_toggled(bool checked)\n{\n\n if(checked)\n {\n ui->pushButton->setText(\"Unlock Mouse\");\n //最好在按钮触发的时候再去获取窗口的位置,避免不必要的错误\n QPoint leftTop = this->mapToGlobal(QPoint(this->rect().left(),\n this->rect().top()));\n QPoint rightBottom = this->mapToGlobal(QPoint(this->rect().right(), \n this->rect().bottom()));\n RECT rect1;\n rect1.bottom = rightBottom.y();\n rect1.right = rightBottom.x();\n rect1.left = leftTop.x();\n rect1.top = leftTop.y();\n ClipCursor(&rect1);\n }\n else\n {\n ui->pushButton->setText(\"LockMouse\");\n ClipCursor(NULL);\n }\n}