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:
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;
}
int CQtTextLayout::GetTotalLineCount( )
{
int nReturnValue = 0;
if( m_pTextCursor )
{
m_pTextCursor->movePosition( QTextCursor::Start );
bool isNotDone = true;
int lineCounter = 0;
while( isNotDone )
{
isNotDone = m_pTextCursor->movePosition( QTextCursor::Down );
lineCounter++;
}
DebugLog( "QT GetTotalLineCount %d", nReturnValue );
}
return nReturnValue;
}
To copy to clipboard, switch view to plain text mode
Bookmarks