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:

Qt Code:
  1. int CQtTextLayout::GetTotalLineCount( )
  2. {
  3. int nReturnValue = 0;
  4.  
  5. if( m_pTextCursor )
  6. {
  7. m_pTextCursor->movePosition( QTextCursor::Start );
  8. bool isNotDone = true;
  9. int lineCounter = 0;
  10. while( isNotDone )
  11. {
  12. isNotDone = m_pTextCursor->movePosition( QTextCursor::Down );
  13. lineCounter++;
  14. }
  15. DebugLog( "QT GetTotalLineCount %d", nReturnValue );
  16. }
  17.  
  18. return nReturnValue;
  19. }
To copy to clipboard, switch view to plain text mode