Implementing hover
Solved
General and Desktop
-
wrote on 26 Feb 2019, 10:43 last edited by
i need to activate hover or implement it whitin PaintEvent() .
i can not use StyleSheet.how can i do it?
-
Hi
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 { Q_OBJECT public: Label(QWidget* parent = Q_NULLPTR) :QLabel("test", parent) {} protected: virtual void enterEvent(QEvent* event) override { event->accept(); qDebug() << "enterEvent" << objectName(); } virtual void leaveEvent(QEvent* event) override { event->accept(); } };
Notice, i used Label here. you might want plain QWidget instead.
-
wrote on 26 Feb 2019, 20:18 last edited by
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) -
wrote on 27 Feb 2019, 08:04 last edited by mahd96
i used in "underMouse()" in paintEvent(). with WA_Hover attribute set.
it works as i need.
1/4