I am wondering what the correct way is to achieve the following: I would like to have the character indices of the start of a line and its length.
At the moment I am abusing (again) the textcursor for that:

m_pTextCursor is a QTextCursor

Qt Code:
  1. void CQtTextLayout::GetLayoutIndicesOfLine( int line, int *start, int *length )
  2. {
  3. if( m_pTextCursor )
  4. {
  5. m_pTextCursor->movePosition( QTextCursor::Start );
  6. for( int i=0; i<line; i++)
  7. {
  8. m_pTextCursor->movePosition( QTextCursor::Down );
  9. }
  10. m_pTextCursor->movePosition( QTextCursor::StartOfLine);
  11. *start = m_pTextCursor->position();
  12. m_pTextCursor->movePosition( QTextCursor::EndOfLine);
  13. *length = m_pTextCursor->position() - *start;
  14. DebugLog( "QT GetLayoutIndicesOfLine %d %d/%d", line, *start, *length );
  15. }
  16. else
  17. {
  18. *start = 0;
  19. *length = 0;
  20. }
  21. }
To copy to clipboard, switch view to plain text mode