PDA

View Full Version : Need a null char for line ends for my TextEdit



tonnot
13th October 2011, 11:59
I have a TextEdit that shows only the lines it can be show (it is for a view-only editor I have ).
I calculate the max_lines = TextEdit.height()/ fontmetrics.height; (I have in mind the margins ).
I need a way to insert the textlines so for the first max_lines -1 I add \n and nothing for the last.

I have a char array, with max_lines size. I give the '\n' value for the first max_lines -1 but I dont know how to give null value to the last,
If I use '\0' , TextEdit shows me the typical vertical rectangle for unknowed characters.

( I use this array because I want to avoid an if statement ).

Any idea how can I do this ?
Thanks.

wysota
13th October 2011, 12:13
Why do you need this \0? It seems you get what you wanted, you insert \0 and so the widget tries to display it (and fails because \0 has no glyph associated with it so the font replaces it with a blank).

tonnot
13th October 2011, 12:33
I need to say the TextEdit that does not make line feed for the last line I insert on it....

wysota
13th October 2011, 13:05
If you don't insert a newline character then it will not make a new line, no additional characters are required.

tonnot
13th October 2011, 13:39
Ok wy.
But I need a method to add or not a linefeed .
I can do this with a 'if' 'am I the last_line' or by prepare a char array for the lines I'm going to show. ( it think that is better to add 100 times a one char that make 100 if checks, isnt it ?

I have \n for the first max_lines-1 and I need to use a correct value for the last , is there any solution ?

Thanks

wysota
13th October 2011, 15:02
I have no idea what you want, sorry. You need to express yourself better.

tonnot
13th October 2011, 16:55
I have a QtextEdit. I use it, initally, to show a file of 1.000.000 of lines which I have 'mapped'. (It is a Qtextedit model-view approach)
Ok, I'm going to show 56 lines. I have 56 lines of data without linefeed end char stored at 'mymap_data' qstring vector.
I use :


txt_editor->document()->clear();
QTextCursor txt_c = QTextCursor(txt_editor->document());
for( int x=0;x<num_lines_to_show;x++)
{
txt_c.insertText(...) ;
}


I have two ways to do the insert:
- Test if x=num_lines_to_show to add or not a \n to the inserteted text.
- Add a 'end_line[]¡ char previously created.
end_lines = new char [line_max] ; (Created every time I have a resize event for my widget contains TextEdit)

I like the second :
txt_c.insertText(mymap_data.at(x)+end_line[x]);
So . I need a valid end_line[] ;

I hope you understand what I want.
Thanks for your time.

wysota
13th October 2011, 19:36
Or you can show all lines and remove the last newline after exiting the loop.
Or you can insert the first line without a newline and then begin each next line with a newline.
Or you can substract one from num_lines_to_show, run a "for" loop against that count adding a newline after each line and then add the last line after you exit the loop.
Or possibly use any different approach that surely exist.

tonnot
13th October 2011, 20:39
Yes, I only was persisted in trying the use of null char, but it seems to be impossible..
Thanks any way.

wysota
13th October 2011, 20:43
I don't see how a null character would have helped you here.