diff options
author | Timur Kristóf <timur.kristof@gmail.com> | 2019-09-27 18:07:41 +0200 |
---|---|---|
committer | Timur Kristóf <timur.kristof@gmail.com> | 2019-11-04 09:39:10 +0200 |
commit | b25c27d37a5d5dded723946900f9a518c38385de (patch) | |
tree | bae23ac214ae9bebb394550ecfb752e138e31c6a /examples | |
parent | bd62eff7ca551dc76cf1ec2e7eef14664f6228a5 (diff) |
Add API to get more information for each line in a QML Text element
Previously there was no way to know what area is occupied by each line
in a QML Text element.
This commit adds new API to expose implicitWidth and isLast
on QQuickTextLine for use in the lineLaidOut signal.
It also adds improved documentation to the lineLaidOut signal and
an example usage of the new API to the text layout example.
An example use case of the new API is eg. to allow embedding
timestamps and indicators within a text paragraph, to enable
creating more efficient layouts.
[ChangeLog][QtQuick][Text] Added new API that exposes implicitWidth,
and isLast on the QQuickTextLine for use in the lineLaidOut signal.
This allows the user to layout other items relative to the lines
of text.
Fixes: QTBUG-78277
Change-Id: Ibc754db17c78efb01468106aba32e30d70d2f4df
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/quick/text/styledtext-layout.qml | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/examples/quick/text/styledtext-layout.qml b/examples/quick/text/styledtext-layout.qml index fe7b40b89b..631a37b493 100644 --- a/examples/quick/text/styledtext-layout.qml +++ b/examples/quick/text/styledtext-layout.qml @@ -78,8 +78,27 @@ Rectangle { line.y -= height - margin line.x = width / 2 + margin } + + if (line.isLast) { + lastLineMarker.x = line.x + line.implicitWidth + lastLineMarker.y = line.y + (line.height - lastLineMarker.height) / 2 + } } //! [layout] + + Rectangle { + id: lastLineMarker + color: "#44cccccc" + width: theEndText.width + margin + height: theEndText.height + margin + + Text { + id: theEndText + text: "THE\nEND" + anchors.centerIn: parent + font.pixelSize: myText.font.pixelSize / 2 + } + } } } |