diff options
-rw-r--r-- | src/quick/items/qquicktextnodeengine.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/quick/items/qquicktextnodeengine.cpp b/src/quick/items/qquicktextnodeengine.cpp index 82bd9cd4ec..19df175115 100644 --- a/src/quick/items/qquicktextnodeengine.cpp +++ b/src/quick/items/qquicktextnodeengine.cpp @@ -477,6 +477,9 @@ void QQuickTextNodeEngine::addTextObject(const QTextBlock &block, const QPointF } } + // Use https://developer.mozilla.org/de/docs/Web/CSS/vertical-align as a reference + // The top/bottom positions are supposed to be higher/lower than the text and reference + // the line height, not the text height (using QFontMetrics) qreal ascent; QTextLine line = block.layout()->lineForTextPosition(pos - block.position()); switch (format.verticalAlignment()) @@ -484,11 +487,10 @@ void QQuickTextNodeEngine::addTextObject(const QTextBlock &block, const QPointF case QTextCharFormat::AlignTop: ascent = line.ascent(); break; - case QTextCharFormat::AlignMiddle: { - QFontMetrics m(format.font()); - ascent = (size.height() - m.xHeight()) / 2; + case QTextCharFormat::AlignMiddle: + // Middlepoint of line (height - descent) + Half object height + ascent = (line.ascent() + line.descent()) / 2 - line.descent() + size.height() / 2; break; - } case QTextCharFormat::AlignBottom: ascent = size.height() - line.descent(); break; |