summaryrefslogtreecommitdiffstats
path: root/doc/src/snippets/code/src_gui_text_qtextlayout.cpp
blob: 548bb783e064670c68229278909110a2fe16a41b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//! [0]
int leading = fontMetrics.leading();
qreal height = 0;
qreal widthUsed = 0;
textLayout.beginLayout();
while (1) {
    QTextLine line = textLayout.createLine();
    if (!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]
QPainter painter(this);
textLayout.draw(&painter, QPoint(0, 0));
//! [1]