PDA

View Full Version : free mouse pointer



raflegan
1st October 2008, 13:48
Hi,
I'm trying to use Qt for a game-like application. I have a QGLWidget doing the OpenGL drawing. Now i want to implement free mouse look (like in a game). I can blend out the mouse cursor using QWidget::setCursor(), but the mouse pointer can't cross the screen edge. So, for example, if I want to turn to one direction, the turning stops when i reach the screen edge, even though I would like it to continue turning.
I have just started programming with Qt some days ago, does anyone have suggestions how to best implement free mouse look in Qt?
I have tried to use Cursor::setPos(), to keep the cursor from reaching the screen edge, but this function generates a mouse move event, which I would have to ignore somehow. Additionally it would probabely not be very safe to call Cursor::setPos() from inside the mouseMoveEvent() handler, which I would have to do.

thanks in advance
raflegan

raflegan
1st October 2008, 14:11
Sorry, I just found a solution, disregard this thread.

If someone is interested, the following solution works for me:


void QGLightViewport::mousePressEvent(QMouseEvent* mouseEvent)
{
mLastMousePos = mouseEvent->globalPos();
setCursor(Qt::BlankCursor);
cursor().setPos(mapToGlobal(rect().center()));
}

void QGLightViewport::mouseMoveEvent(QMouseEvent* mouseEvent)
{
QPoint mouseHomePos = mapToGlobal(rect().center());
QPoint mouseMove = (mouseEvent->globalPos() - mouseHomePos);
if (mouseMove.isNull()) // mouse didn't move
return;

// do things depending on the mouse move

cursor().setPos(mapToGlobal(rect().center()));
}


void QGLightViewport::mouseReleaseEvent(QMouseEvent* mouseEvent)
{
cursor().setPos(mLastMousePos);
unsetCursor();
}