diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-03-10 16:29:33 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-03-11 12:12:51 +0000 |
commit | 4e1c2ac86179f8ff524468aa7fccfabc656a238a (patch) | |
tree | 5aca7a971f3df950d7bf61219a57641e32b9a2f8 /src/templates/qquicklabel.cpp | |
parent | 2e79c79bed863b5abc3ce55a4552fd9d32a7d83a (diff) |
Fix font comparisons
When inheritance of explicitly set font attributes is involved, it is
important to compare the resolve mask in addition to comparing the
attribute values to avoid losing the information whether a specific
attribute is set explicitly.
For example, QFont::operator==() returns true for two fonts that
are both bold regardless of whether only one of them has explicit
weight set. Therefore, setFont() must not ignore fonts resolve mask.
Furthermore, the fontChanged() notifier must be emitted only if the
actual attribute values change, not if only the resolve mask changes.
Change-Id: I2eb7a071c0eaecd2f8d2f6074c4ce6ed6764a6e9
Task-number: QTBUG-50984
Task-number: QTBUG-51696
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
Diffstat (limited to 'src/templates/qquicklabel.cpp')
-rw-r--r-- | src/templates/qquicklabel.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/templates/qquicklabel.cpp b/src/templates/qquicklabel.cpp index 13ff3a6e..7de520d9 100644 --- a/src/templates/qquicklabel.cpp +++ b/src/templates/qquicklabel.cpp @@ -113,9 +113,12 @@ void QQuickLabelPrivate::resolveFont() if (sourceFont.resolve() == resolvedFont.resolve() && sourceFont == resolvedFont) return; + const bool changed = sourceFont != resolvedFont; + q->QQuickText::setFont(resolvedFont); - emit q->fontChanged(); + if (changed) + emit q->fontChanged(); } void QQuickLabelPrivate::_q_textChanged(const QString &text) @@ -158,7 +161,7 @@ QFont QQuickLabel::font() const void QQuickLabel::setFont(const QFont &font) { Q_D(QQuickLabel); - if (d->sourceFont == font) + if (d->sourceFont.resolve() == font.resolve() && d->sourceFont == font) return; // Determine which font is inherited from this control's ancestors and @@ -170,9 +173,12 @@ void QQuickLabel::setFont(const QFont &font) if (d->sourceFont.resolve() == resolvedFont.resolve() && d->sourceFont == resolvedFont) return; + const bool changed = d->sourceFont != resolvedFont; + QQuickText::setFont(font); - emit fontChanged(); + if (changed) + emit fontChanged(); } /*! |