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
void CQtTextLayout::GetLayoutIndicesOfLine( int line, int *start, int *length )
{
if( m_pTextCursor )
{
for( int i=0; i<line; i++)
{
}
m_pTextCursor
->movePosition
( QTextCursor::StartOfLine);
*start = m_pTextCursor->position();
*length = m_pTextCursor->position() - *start;
DebugLog( "QT GetLayoutIndicesOfLine %d %d/%d", line, *start, *length );
}
else
{
*start = 0;
*length = 0;
}
}
void CQtTextLayout::GetLayoutIndicesOfLine( int line, int *start, int *length )
{
if( m_pTextCursor )
{
m_pTextCursor->movePosition( QTextCursor::Start );
for( int i=0; i<line; i++)
{
m_pTextCursor->movePosition( QTextCursor::Down );
}
m_pTextCursor->movePosition( QTextCursor::StartOfLine);
*start = m_pTextCursor->position();
m_pTextCursor->movePosition( QTextCursor::EndOfLine);
*length = m_pTextCursor->position() - *start;
DebugLog( "QT GetLayoutIndicesOfLine %d %d/%d", line, *start, *length );
}
else
{
*start = 0;
*length = 0;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks