Results 1 to 3 of 3

Thread: How can I follow the mouse?

  1. #1
    Join Date
    Mar 2009
    Posts
    2
    Qt products
    Qt4

    Default How can I follow the mouse?

    Hi all,

    I have a QLabel and I want that, that QLabel follow the mouse movement of the user.

    Currently I have the following Code:

    Qt Code:
    1. label = new QLabel(this);
    2.  
    3. void CSomeClass::mouseMoveEvent( QMouseEvent *event )
    4. {
    5. QPoint currentPos = QWidget::mapFromGlobal(QCursor::pos());
    6. int x = currentPos.x();
    7. int y = currentPos.y();
    8. label->setText("testje");
    9. label->setGeometry(x,y, 50, 50);
    10. label->show();
    11. }
    To copy to clipboard, switch view to plain text mode 

    Problem
    This works fine but the problem is that the movement is too slow!
    The text halts everytime.

    Does anyone know how to solve this?
    How do I get a mouse movement with text beneath that follows directly the cursor?

    Thanx!
    Last edited by wysota; 15th April 2009 at 09:49. Reason: missing [code] tags

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I follow the mouse?

    You could also try for QToolTip::showText.

    Also what class are you using ? you could also think of drawing the message in your class. It could result in faster display.
    For eg say on mouse move u generate the message variable m_message;
    And in paint event, you check if m_message is empty or not. If not empty,draw the message. Oh yea, you would need to store current mouse pos too, isnt it

  3. #3
    Join Date
    Mar 2009
    Posts
    2
    Qt products
    Qt4

    Default Re: How can I follow the mouse?

    Thank you for your quick replay.. It seems that the movement is now quick enough.
    I have changed the drawing to the paintEvent like you said.

    Thanks a lot!

Similar Threads

  1. Changing mouse grabbing behavior?
    By FlyingSaucrDude in forum Qt Programming
    Replies: 0
    Last Post: 11th November 2008, 02:04
  2. Mouse position on screen
    By Nippler in forum Qt Programming
    Replies: 3
    Last Post: 7th August 2008, 15:22
  3. mouse moving don't produce mouse events
    By coralbird in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2006, 07:13
  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.