aboutsummaryrefslogtreecommitdiffstats
path: root/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextlayout.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextlayout.cpp')
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextlayout.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextlayout.cpp b/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextlayout.cpp
new file mode 100644
index 000000000..267f195b9
--- /dev/null
+++ b/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextlayout.cpp
@@ -0,0 +1,23 @@
+//! [0]
+leading = fontMetrics.leading()
+height = 0
+widthUsed = 0
+textLayout.beginLayout()
+while True:
+ line = textLayout.createLine()
+ if not line.isValid():
+ break
+
+ line.setLineWidth(lineWidth)
+ height += leading
+ line.setPosition(QPointF(0, height))
+ height += line.height()
+ widthUsed = qMax(widthUsed, line.naturalTextWidth())
+textLayout.endLayout()
+//! [0]
+
+
+//! [1]
+painter = QPainter(self)
+textLayout.draw(painter, QPoint(0, 0))
+//! [1]