class TestTooltip : public QWidget { Q_OBJECT public: TestTooltip(const QString &message = QString(), QWidget* parent = nullptr); virtual ~TestTooltip(); public slots: /// Redraws the tooltip next to wid position /// Should be called when the window/widget moves or resizes /// \param wid a widget. The tooltip will take the widget position and /// appear just above it void updateTooltip(QWidget *wid); private: QLabel *m_msgLabel; }; class LabelWithTooltip final : public QLabel { Q_OBJECT public: explicit LabelWithTooltip(const QString &text = QString(), QWidget *parent = nullptr); ~LabelWithTooltip(); LabelWithTooltip(const LabelWithTooltip &) = delete; LabelWithTooltip(LabelWithTooltip &&) = delete; LabelWithTooltip &operator=(const LabelWithTooltip &) = delete; LabelWithTooltip &operator=(LabelWithTooltip &&) = delete; QSize sizeHint() const override; protected: void showEvent(QShowEvent *event) override final; void resizeEvent(QResizeEvent *event) override final; void moveEvent(QMoveEvent *event) override final; void enterEvent(QEnterEvent *event) override final; void leaveEvent(QEvent *event) override final; private: TestTooltip *m_tooltip; };