PDA

View Full Version : How can I follow the mouse?



T.I.M
15th April 2009, 09:29
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:


label = new QLabel(this);

void CSomeClass::mouseMoveEvent( QMouseEvent *event )
{
QPoint currentPos = QWidget::mapFromGlobal(QCursor::pos());
int x = currentPos.x();
int y = currentPos.y();
label->setText("testje");
label->setGeometry(x,y, 50, 50);
label->show();
}

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!

aamer4yu
15th April 2009, 09:36
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 :)

T.I.M
15th April 2009, 09:42
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!