Getting real number of lines (lineCount) of a QTextDocument
The QTextDocument is rendering some HTML code and gets rendered on a QImage.
For some reason myDocument->lineCount() is returning the number of paragraphs but not the actual number of lines. The width of the QTextDocument is set and it is displayed correctly.
I saw some suggestion for converting the text to plaintext and count the newlines or something along the lines, but that is not satisfactory for me.
For now I am using the following code to get the number of lines abusing a textcursor, but I am wondering whether there is a better way to do that:
Code:
int CQtTextLayout::GetTotalLineCount( )
{
int nReturnValue = 0;
if( m_pTextCursor )
{
bool isNotDone = true;
int lineCounter = 0;
while( isNotDone )
{
isNotDone
= m_pTextCursor
->movePosition
( QTextCursor::Down );
lineCounter++;
}
DebugLog( "QT GetTotalLineCount %d", nReturnValue );
}
return nReturnValue;
}