Important: Please read the Qt Code of Conduct -

Implementing hover

  • i need to activate hover or implement it whitin PaintEvent() .
    i can not use StyleSheet.

    how can i do it?

  • Lifetime Qt Champion

    You need to subclass and override enterEvent/leaveEvent
    Then you can use a variable to know if you been hovered and paint differently in paintEvent.

    class Label : public QLabel {
      Label(QWidget* parent = Q_NULLPTR) :QLabel("test", parent) {}  
      virtual void enterEvent(QEvent* event) override {
        qDebug() << "enterEvent" << objectName();
      virtual void leaveEvent(QEvent* event) override {

    Notice, i used Label here. you might want plain QWidget instead.

  • Answer above is more flexible, but may be overkill if your need to hover is more trivial (like displaying tool tip text), then you can simply set the setToolTip(Qstring) for each widget where you want a tip to pop up on hover. See

    QWidget::setToolTip(QString& str)
    QWidget::setToolTipDuration(int msec)

  • i used in "underMouse()" in paintEvent(). with WA_Hover attribute set.
    it works as i need.

Log in to reply