Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I implement QHoverEvent in Qt?
    primarykey
    data
    text
    <p>I'm just learning Qt with C++. I have successfully implemented signals and slots to trap standard events like <code>ButtonPushed()</code>, etc. However, I want to have a function called when I mouse over and mouse out of a <code>QLabel</code>. It looks like <a href="http://doc.qt.io/qt-4.8/qhoverevent.html" rel="nofollow noreferrer">QHoverEvent</a> will do what I need, but I can't seem to find any tutorials or examples on how to implement this. Is it done the same way as signals and slots?. I tried:</p> <pre><code>connect(ui.lbl_test, SIGNAL(QHoverEvent), this, SLOT(TestFunc(QEvent::Type type, const QPoint &amp; pos, const QPoint &amp; oldPos))); </code></pre> <p>.. but the function didn't get called when I hovered over the label.</p> <p>Here is the function, listed in the header file as a public slot:</p> <pre><code>void MyDialog::TestFunc(QEvent::Type type, const QPoint &amp; pos, const QPoint &amp; oldPos) { QMessageBox::information(this, tr("Hey"), tr("Listen!")); } </code></pre> <p>Can anyone help me figure this out or point me to a good example?</p> <p>EDIT:</p> <p>After reading a post below, I found no <code>setFlag()</code> member to call for my label widget, but I did try:</p> <pre><code> ui.lbl_test-&gt;setMouseTracking(true); connect(ui.lbl_test, SIGNAL(ui.lbl_test-&gt;mouseMoveEvent()), this, SLOT(TestFunc(QMouseEvent *event))); </code></pre> <p>And updated <code>TestFunc()</code> accordingly. But still nothing happens when I mouse over.</p> <p>After looking I am not sure <code>QLabel</code> even inherits the mouseMoveEvent() even from <code>QWidget</code>. If this is true, is there a widget that does, or a list of objects that inherit it somewhere?. All I can tell from the documentation on their site is how many inherited functions an object has..</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload