PDA

View Full Version : How to handle mousehover event on a label?



moiit
7th December 2010, 17:08
While mouse hovers on a label, then a window with a clickable link pops up.
When the link is clicked, or mouse leave the label, or mouse leave the popup window,
the popup window will be closed.

How to implement it?

Any help is appreciated.

Lykurg
7th December 2010, 18:17
Reimp the handlers QWidget::enterEvent() and QWidget::leaveEvent(). Open and close the pop up there.

moiit
8th December 2010, 13:09
Reimp the handlers QWidget::enterEvent() and QWidget::leaveEvent(). Open and close the pop up there.

Thanks for your advice.
I tried, have no lucky.
Can you post the codes up if possible?
Thanks again.

Lykurg
8th December 2010, 13:26
what have you tried so far and how does your code look like?

dominate
28th January 2011, 00:41
You should make a new class inheriting from QLabel class.
In the new class, put the declaration of Widget events under the "signals:".
Then, connect the signals to your slots.
For example:

class myClass : public QLabel
...
signals:
void mouseReleaseEvent(QMouseEvent *);
...
public slots:
void mySlot();

in the constructor:
connect(this, SIGNAL(mouseReleaseEvent(QMouseEvent*)), this, SLOT(mySlot()));

ComaWhite
28th January 2011, 03:16
You should make a new class inheriting from QLabel class.
In the new class, put the declaration of Widget events under the "signals:".
Then, connect the signals to your slots.
For example:

class myClass : public QLabel
...
signals:
void mouseReleaseEvent(QMouseEvent *);
...
public slots:
void mySlot();

in the constructor:
connect(this, SIGNAL(mouseReleaseEvent(QMouseEvent*)), this, SLOT(mySlot()));

That is totally wrong. You have to overload the mouseReleaseEvent. Not connect it to a slot.