[PyQt] Reach a line in a QTextEdit
cyril Romain
c.romain at laposte.net
Sun Mar 29 13:33:36 BST 2009
projetmbc at club-internet.fr wrote:
> 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