Results 1 to 2 of 2

Thread: free mouse pointer

  1. #1
    Join Date
    Oct 2008
    Qt products

    Default free mouse pointer

    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

  2. #2
    Join Date
    Oct 2008
    Qt products

    Default Re: free mouse pointer

    Sorry, I just found a solution, disregard this thread.

    If someone is interested, the following solution works for me:
    Qt Code:
    1. void QGLightViewport::mousePressEvent(QMouseEvent* mouseEvent)
    2. {
    3. mLastMousePos = mouseEvent->globalPos();
    4. setCursor(Qt::BlankCursor);
    5. cursor().setPos(mapToGlobal(rect().center()));
    6. }
    8. void QGLightViewport::mouseMoveEvent(QMouseEvent* mouseEvent)
    9. {
    10. QPoint mouseHomePos = mapToGlobal(rect().center());
    11. QPoint mouseMove = (mouseEvent->globalPos() - mouseHomePos);
    12. if (mouseMove.isNull()) // mouse didn't move
    13. return;
    15. // do things depending on the mouse move
    17. cursor().setPos(mapToGlobal(rect().center()));
    18. }
    21. void QGLightViewport::mouseReleaseEvent(QMouseEvent* mouseEvent)
    22. {
    23. cursor().setPos(mLastMousePos);
    24. unsetCursor();
    25. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QTextEdit: get word under the mouse pointer?
    By zorro68 in forum Qt Programming
    Replies: 4
    Last Post: 13th November 2009, 15:42
  2. *** glibc detected ***: free(): invalid pointer
    By codebehind in forum Qt Programming
    Replies: 4
    Last Post: 20th September 2008, 22:45
  3. How can I hide the mouse pointer?
    By dimaz in forum Qt Programming
    Replies: 2
    Last Post: 22nd August 2008, 19:08
  4. Replies: 2
    Last Post: 24th July 2006, 18:36
  5. QStackerWidget and mouse events
    By high_flyer in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2006, 19:25


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.