我正在将我的图形引擎从Freeglut转移到Qt.我的窗口类继承自QWindow.我将相对鼠标位置设置到窗口中心并隐藏光标时遇到问题.在freeglut中,代码如下所示:
glutWarpPointer((glutGet(GLUT_WINDOW_WIDTH) / 2), (glutGet(GLUT_WINDOW_HEIGHT) / 2));
glutSetCursor(GLUT_CURSOR_NONE);
Run Code Online (Sandbox Code Playgroud)
我正在尝试这样的事情:
this->cursor().setPos((width() / 2), (height() / 2)); // this seems to set an absolute (global) position
this->cursor().setShape(Qt::BlankCursor); // doesn't work
Run Code Online (Sandbox Code Playgroud)
怎么实现呢?
Fra*_*eld 10
您的代码没有任何效果,因为您正在编辑临时副本.
看看签名:QCursor QWidget::cursor() const.游标对象按值返回.要应用游标更改,您必须通过返回修改后的对象setCursor().要从本地坐标到全局坐标,请使用mapToGlobal():
QCursor c = cursor();
c.setPos(mapToGlobal(QPoint(width() / 2, height() / 2)));
c.setShape(Qt::BlankCursor);
setCursor(c);
Run Code Online (Sandbox Code Playgroud)