PDA

View Full Version : Get Character



bismitapadhy
15th July 2009, 10:36
How can i get the next and previous character content from cursor posion in a QTextEdit?

yogeshgokul
15th July 2009, 10:39
try
QTextCursor :: position ()

bismitapadhy
15th July 2009, 10:43
try
QTextCursor :: position ()it will return the position.But i want the what is the next and previous character content not the position

yogeshgokul
15th July 2009, 11:09
it will return the position.But i want the what is the next and previous character content not the position

Should be damm easy.


textEdit->toPlainText().at(position-1);
textEdit->toPlainText().at(position+1);

wagmare
15th July 2009, 11:13
after selecting the character or by default position ..?

yogeshgokul
15th July 2009, 11:15
after selecting the character or by default position ..?
:confused::confused:

wagmare
15th July 2009, 11:20
:confused::confused:

but how can we get the char the QTextCursor currently positioned ..
ex:
hell|o world

think "|" as cursor position .. it is in middle of "l" and "o" .. so how can i get that two char or either of it ...

the position is dynamic at run time .. and the position is not hard coded value ..

any way to implement ..

and u answered it .. thank you very much ...

yogeshgokul
15th July 2009, 11:37
but how can we get the char the QTextCursor currently positioned ..
ex:
hell|o world

think "|" as cursor position .. it is in middle of "l" and "o" .. so how can i get that two char or either of it ...

the position is dynamic at run time .. and the position is not hard coded value ..

any way to implement ..




int pos = TextEdit->textCursor().position();
QChar cPrev = TextEdit->toPlainText().at(pos);
QChar cNext = TextEdit->toPlainText().at(pos+1);