Results 1 to 10 of 10

Thread: Need a null char for line ends for my TextEdit

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Need a null char for line ends for my TextEdit

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Need a null char for line ends for my TextEdit

    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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Need a null char for line ends for my TextEdit

    I need to say the TextEdit that does not make line feed for the last line I insert on it....

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Need a null char for line ends for my TextEdit

    If you don't insert a newline character then it will not make a new line, no additional characters are required.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Need a null char for line ends for my TextEdit

    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

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Need a null char for line ends for my TextEdit

    I have no idea what you want, sorry. You need to express yourself better.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Need a null char for line ends for my TextEdit

    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 :
    Qt Code:
    1. txt_editor->document()->clear();
    2. QTextCursor txt_c = QTextCursor(txt_editor->document());
    3. for( int x=0;x<num_lines_to_show;x++)
    4. {
    5. txt_c.insertText(...) ;
    6. }
    To copy to clipboard, switch view to plain text mode 

    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.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Need a null char for line ends for my TextEdit

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Need a null char for line ends for my TextEdit

    Yes, I only was persisted in trying the use of null char, but it seems to be impossible..
    Thanks any way.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Need a null char for line ends for my TextEdit

    I don't see how a null character would have helped you here.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QTreeView find out when the drag operation ends
    By mentalmushroom in forum Qt Programming
    Replies: 2
    Last Post: 4th October 2011, 07:37
  2. Replies: 4
    Last Post: 30th September 2011, 14:00
  3. Insert line to textedit
    By wirasto in forum Qt Programming
    Replies: 1
    Last Post: 18th December 2009, 15:59
  4. Converting QString to char* in onl line
    By hubbobubbo in forum Qt Programming
    Replies: 10
    Last Post: 11th December 2009, 11:45
  5. How can I paint a line in TextEdit on QT-4.3.2?
    By cslijy in forum Qt Programming
    Replies: 2
    Last Post: 23rd November 2007, 08:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.