Index: qtooltip.cpp =================================================================== --- qtooltip.cpp (revision 3302) +++ qtooltip.cpp (working copy) @@ -120,7 +120,7 @@ { Q_OBJECT public: - QTipLabel(const QString &text, QWidget *w); + QTipLabel(QWidget *w); ~QTipLabel(); static QTipLabel *instance; @@ -137,6 +137,7 @@ void restartExpireTimer(); bool tipChanged(const QPoint &pos, const QString &text, QObject *o); void placeTip(const QPoint &pos, QWidget *w); + void setStyleSheetParent(QWidget *w); static int getTipScreen(const QPoint &pos, QWidget *w); protected: @@ -166,7 +167,7 @@ QTipLabel *QTipLabel::instance = 0; -QTipLabel::QTipLabel(const QString &text, QWidget *w) +QTipLabel::QTipLabel(QWidget *w) #ifndef QT_NO_STYLE_STYLESHEET : QLabel(w, Qt::ToolTip | Qt::BypassGraphicsProxyWidget), styleSheetParent(0), widget(0) #else @@ -187,7 +188,6 @@ setWindowOpacity(style()->styleHint(QStyle::SH_ToolTipLabel_Opacity, 0, this) / qreal(255.0)); setMouseTracking(true); fadingOut = false; - reuseTip(text); } void QTipLabel::restartExpireTimer() @@ -197,16 +197,33 @@ hideTimer.stop(); } -void QTipLabel::reuseTip(const QString &text) +void QTipLabel::setStyleSheetParent(QWidget *w) { #ifndef QT_NO_STYLE_STYLESHEET - if (styleSheetParent){ - disconnect(styleSheetParent, SIGNAL(destroyed()), - QTipLabel::instance, SLOT(styleSheetParentDestroyed())); - styleSheetParent = 0; + if (styleSheetParent){ + disconnect(styleSheetParent, SIGNAL(destroyed()), + this, SLOT(styleSheetParentDestroyed())); + styleSheetParent = 0; + } + + if (testAttribute(Qt::WA_StyleSheet) || (w && qobject_cast(w->style()))) { + //the stylesheet need to know the real parent + setProperty("_q_stylesheet_parent", QVariant::fromValue(w)); + //we force the style to be the QStyleSheetStyle, and force to clear the cache as well. + setStyleSheet(QLatin1String("/* */")); + + // Set up for cleaning up this later... + styleSheetParent = w; + if (w) { + connect(w, SIGNAL(destroyed()), + this, SLOT(styleSheetParentDestroyed())); } -#endif + } +#endif //QT_NO_STYLE_STYLESHEET +} +void QTipLabel::reuseTip(const QString &text) +{ setWordWrap(Qt::mightBeRichText(text)); setText(text); QFontMetrics fm(font()); @@ -350,23 +367,6 @@ void QTipLabel::placeTip(const QPoint &pos, QWidget *w) { -#ifndef QT_NO_STYLE_STYLESHEET - if (testAttribute(Qt::WA_StyleSheet) || (w && qobject_cast(w->style()))) { - //the stylesheet need to know the real parent - QTipLabel::instance->setProperty("_q_stylesheet_parent", QVariant::fromValue(w)); - //we force the style to be the QStyleSheetStyle, and force to clear the cache as well. - QTipLabel::instance->setStyleSheet(QLatin1String("/* */")); - - // Set up for cleaning up this later... - QTipLabel::instance->styleSheetParent = w; - if (w) { - connect(w, SIGNAL(destroyed()), - QTipLabel::instance, SLOT(styleSheetParentDestroyed())); - } - } -#endif //QT_NO_STYLE_STYLESHEET - - #ifdef Q_WS_MAC // When in full screen mode, there is no Dock nor Menu so we can use // the whole screen for displaying the tooltip. However when not in @@ -452,6 +452,7 @@ if (w) localPos = w->mapFromGlobal(pos); if (QTipLabel::instance->tipChanged(localPos, text, w)){ + QTipLabel::instance->setStyleSheetParent(w); QTipLabel::instance->reuseTip(text); QTipLabel::instance->setTipRect(w, rect); QTipLabel::instance->placeTip(pos, w); @@ -462,12 +463,14 @@ if (!text.isEmpty()){ // no tip can be reused, create new tip: #ifndef Q_WS_WIN - new QTipLabel(text, w); // sets QTipLabel::instance to itself + new QTipLabel(w); // sets QTipLabel::instance to itself #else // On windows, we can't use the widget as parent otherwise the window will be // raised when the tooltip will be shown - new QTipLabel(text, QApplication::desktop()->screen(QTipLabel::getTipScreen(pos, w))); + new QTipLabel(QApplication::desktop()->screen(QTipLabel::getTipScreen(pos, w))); #endif + QTipLabel::instance->setStyleSheetParent(w); + QTipLabel::instance->reuseTip(text); QTipLabel::instance->setTipRect(w, rect); QTipLabel::instance->placeTip(pos, w); QTipLabel::instance->setObjectName(QLatin1String("qtooltip_label"));