Results 1 to 2 of 2

Thread: free mouse pointer

  1. #1
    Join Date
    Oct 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default free mouse pointer

    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

  2. #2
    Join Date
    Oct 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    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. }
    7.  
    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;
    14.  
    15. // do things depending on the mouse move
    16.  
    17. cursor().setPos(mapToGlobal(rect().center()));
    18. }
    19.  
    20.  
    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, 16:42
  2. *** glibc detected ***: free(): invalid pointer
    By codebehind in forum Qt Programming
    Replies: 4
    Last Post: 20th September 2008, 23:45
  3. How can I hide the mouse pointer?
    By dimaz in forum Qt Programming
    Replies: 2
    Last Post: 22nd August 2008, 20:08
  4. Replies: 2
    Last Post: 24th July 2006, 19:36
  5. QStackerWidget and mouse events
    By high_flyer in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2006, 20:25

Bookmarks

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.