PDA

View Full Version : QTextEdit : adding Text at the Same Location



Saptarshi4031
1st July 2010, 13:29
I am writing an application for Extraction of file.
The text Editor is supposed to show File Name and amount of data extracted .
This is How it should look :

File Name :x
Time Start :

Completed <var> % of ConstantSize

The variable var is continually varied .

QTextCursor cursor(TEXT->textCursor())
pos=cursor.position();
TEXT->setTEXTCursor(cursor);
TEXT->setText(var);

However Each Time The Text is written it is clearing up the screen.
I have tried insertPlaintext. That is appending.

Inputs appreciated..

high_flyer
1st July 2010, 14:13
You are not doin anything with the cursor.
You create a copy of the cursor from the document, you read the position (but don't do with it anything), and then set the cursor back as it was.

What you want is:
1. get the correct position of the text you want to replace
2. select it .
3. use QTextCursor::insertText() to overwrite the old (now selected) value

That is one way.
There are others way as well.

See QTextCursor for more details, they have example code in there too.

Saptarshi4031
1st July 2010, 14:26
Sorri I missed one line to which you were referring,

QTextCursor cursor(TEXT->textCursor())
pos=cursor.position();
cursor.setPosition(pos,cursor.MoveAnchor);
TEXT->setTEXTCursor(cursor);
TEXT->setText(var);

high_flyer
2nd July 2010, 09:04
Ok, but if you read my post you see that its not the only problem.
Try what I suggested.