void mouseMoveEvent(QMouseEvent *e);
void resizeEvent(QResizeEvent *e);
+#ifndef QT_NO_STYLE_STYLESHEET
+public slots:
+ /** \internal
+ Cleanup the _q_stylesheet_parent propery.
+ */
+ void styleSheetParentDestroyed() {
+ setProperty("_q_stylesheet_parent", QVariant());
+ styleSheetParent = 0;
+ }
+
+private:
+ QWidget *styleSheetParent;
+#endif
+
private:
QWidget *widget;
QRect rect;
QTipLabel *QTipLabel::instance = 0;
QTipLabel::QTipLabel(const QString &text, QWidget *w)
+#ifndef QT_NO_STYLE_STYLESHEET
+ : QLabel(w, Qt::ToolTip | Qt::BypassGraphicsProxyWidget), styleSheetParent(0), widget(0)
+#else
: QLabel(w, Qt::ToolTip | Qt::BypassGraphicsProxyWidget), widget(0)
+#endif
{
delete instance;
instance = this;
void QTipLabel::reuseTip(const QString &text)
{
+#ifndef QT_NO_STYLE_STYLESHEET
+ if (styleSheetParent){
+ disconnect(styleSheetParent, SIGNAL(destroyed()),
+ QTipLabel::instance, SLOT(styleSheetParentDestroyed()));
+ styleSheetParent = 0;
+ }
+#endif
+
setWordWrap(Qt::mightBeRichText(text));
setText(text);
QFontMetrics fm(font());
void QTipLabel::placeTip(const QPoint &pos, QWidget *w)
{
#ifndef QT_NO_STYLE_STYLESHEET
- if (w) {
- setStyleSheet(w->styleSheet());
+ if (testAttribute(Qt::WA_StyleSheet) || (w && qobject_cast<QStyleSheetStyle *>(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
// Style rules
#define WIDGET(x) (static_cast<QWidget *>(x.ptr))
+static inline QWidget *parentWidget(const QWidget *w)
+{
+ if(qobject_cast<const QLabel *>(w) && qstrcmp(w->metaObject()->className(), "QTipLabel") == 0) {
+ QWidget *p = qvariant_cast<QWidget *>(w->property("_q_stylesheet_parent"));
+ if (p)
+ return p;
+ }
+ return w->parentWidget();
+}
+
class QStyleSheetStyleSelector : public StyleSelector
{
public:
bool isNullNode(NodePtr node) const
{ return node.ptr == 0; }
NodePtr parentNode(NodePtr node) const
- { NodePtr n; n.ptr = isNullNode(node) ? 0 : WIDGET(node)->parentWidget(); return n; }
+ { NodePtr n; n.ptr = isNullNode(node) ? 0 : parentWidget(WIDGET(node)); return n; }
NodePtr previousSiblingNode(NodePtr) const
{ NodePtr n; n.ptr = 0; return n; }
NodePtr duplicateNode(NodePtr node) const
}
QVector<QCss::StyleSheet> widgetSs;
- for (const QWidget *wid = w; wid; wid = wid->parentWidget()) {
+ for (const QWidget *wid = w; wid; wid = parentWidget(wid)) {
if (wid->styleSheet().isEmpty())
continue;
StyleSheet ss;