如何在特定行中打印 QString
How to print QString in specific line
我通过QTextLayout
知道了如何计算Qt中的行数。我想分别打印每一行。这是我的代码:
QTextLayout *Layout = getMessageTextLayout(text,option,Width);
for (int j = 0; j < Layout->lineCount(); j++)
{
QTextLine tl = Layout->lineAt(j);
for (int k = tl.textStart() ; tl.textLength() ; k++)
{
qDebug()<<"text in line = "<<j;
qDebug()<<text;
}
}
例如,我有这个 QString
:
*11111 1114 1111111 9111111111323154 6542312312222222 22222222222222212 3123
12222222 222222 222133 33333333333 33333333 333333 333333333333333 33333333
3333333333333 3333333 33333331453 4654365464 5645 546 54 6 546 5464 4533243*
我想打印第二行:
12222222 222222 222133 33333333333 33333333 333333 333333333333333 33333333
如何操作?
您可以使用用于创建 QTextLayout 的 QString;
Layout->text().mid(tl.textStart(), tl.textLength())
我通过QTextLayout
知道了如何计算Qt中的行数。我想分别打印每一行。这是我的代码:
QTextLayout *Layout = getMessageTextLayout(text,option,Width);
for (int j = 0; j < Layout->lineCount(); j++)
{
QTextLine tl = Layout->lineAt(j);
for (int k = tl.textStart() ; tl.textLength() ; k++)
{
qDebug()<<"text in line = "<<j;
qDebug()<<text;
}
}
例如,我有这个 QString
:
*11111 1114 1111111 9111111111323154 6542312312222222 22222222222222212 3123
12222222 222222 222133 33333333333 33333333 333333 333333333333333 33333333
3333333333333 3333333 33333331453 4654365464 5645 546 54 6 546 5464 4533243*
我想打印第二行:
12222222 222222 222133 33333333333 33333333 333333 333333333333333 33333333
如何操作?
您可以使用用于创建 QTextLayout 的 QString;
Layout->text().mid(tl.textStart(), tl.textLength())