PDA

View Full Version : QTextEdit



titoaii
13th April 2010, 21:41
Hello everyone,

I'm trying to make the porting from qt3 to qt4 of one program. Q3TextEdit is used in the first one and it returns the cursor position as (paragraph, index) and now I've found the problem that in qt4 I don't know how to get them.
Can anybody help me? Can anybody tell me how to get the paragraph and the index in the paragraph??

Thank you very much in advance! (and sorry for my bad english :) )

JohannesMunk
13th April 2010, 22:14
Hi!



QTextEdit* te = new QTextEdit()
..
QTextCursor cursor = te->textCursor();
int paragraph = cursor.blockNumber();

// Raw position in document
//cursor.position();

// Position from linestart = your index?
int index = cursor.columnNumber();

HIH

See: QTextCursor!

Johannes

titoaii
15th April 2010, 01:34
Thank you Johannes,

Now I've found another problem, when I want to set the cursor in a line "line" and in a column "index", I've just tried, to do the following:


QTextEdit * editor;
//Moves the cursor to the beginning of the document
editor->textCursor().setPosition(0,QTextCursor::MoveAnchor );
//Now moves the cursor to the line "line" and in the column "index"
editor->textCursor().movePosition(QTextCursor::Down, QTextCursor::MoveAnchor,line-1);
editor->textCursor().movePosition(QTextCursor::NextCharact er, QTextCursor::MoveAnchor, index);


However, everything I get is the cursor at the same position as the one before the execution of this code.
I suppose I'm doing it in a bad way. But if you or any can help me, it could be awesome :)

Thank you!

JohannesMunk
15th April 2010, 09:29
Try:


QTextEdit * editor;
//Moves the cursor to the beginning of the document
QTextCursor tc = editor->textCursor();
tc.setPosition(0,QTextCursor::MoveAnchor);
//Now moves the cursor to the line "line" and in the column "index"
tc.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor,line-1);
tc.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, index);
editor->setTextCursor(tc);


Johannes