[PyQt] Reach a line in a QTextEdit

projetmbc at club-internet.fr projetmbc at club-internet.fr
Sun Mar 29 17:11:58 BST 2009


The first method works very well. 

Thanks a lot !
Christophe.


>> I would like to go for example to the fourth line in a QTextEdit. Is-it 
possible 
>> to do that directly or must I have to walk along the three first lines so 
as to go 
>> to the start of the fourth one ?
>>   
>
>Use either:
> 1. QTextEdit::moveCursor(), but you need a for loop to go up/down for 
>multiple lines. Example:
>       editor = QtGui.QTextEdit()
>       [...]
>       for l in range(4):
>            editor.moveCursor(QtGui.QTextCursor.Down, 
>QtGui.QTextCursor.MoveAnchor)
>
> 2. QTextEdit::textCursor() to get the cursor, then 
>QTextCursor::movePosition() and then QTextEdit::setTextCursor() so that 
>it takes effects. Example:
>       editor = QtGui.QTextEdit()
>       [...]
>       cursor = editor.textCursor()
>       cursor.movePosition(QtGui.QTextCursor.Down, 
>QtGui.QTextCursor.MoveAnchor, 4)
>       editor.setTextCursor(cursor)
> 
>Regards,
>
>  Cyril
>




More information about the PyQt mailing list