Results 1 to 2 of 2

Thread: Delete line qtextedit

  1. #1

    Default Delete line qtextedit

    Hi


    How to find and delete line/block from qtextedit which content for example Char 'A'.



    Regards
    Artur

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Delete line qtextedit

    Hope this should help
    Qt Code:
    1. QTextEdit textEdit;
    2.  
    3. textEdit.setPlainText(
    4. "How are you today\n"
    5. "I am not A Visible\n"
    6. "I am not a good\n"
    7. "I am A\n"
    8. "I am a\n"
    9. "I am B");
    10.  
    11. QStringList lines = textEdit.toPlainText().split("\n");
    12.  
    13. int i = 0;
    14.  
    15. while(i < lines.size())
    16. {
    17. QString line = lines.at(i);
    18.  
    19. if(line.contains('A'))
    20. {
    21. lines.removeAt(i);
    22. }
    23. else
    24. {
    25. i++;
    26. }
    27. }
    28.  
    29. textEdit.setPlainText(lines.join("\n"));
    30.  
    31. textEdit.show();
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. QTextEdit New line after append
    By FreddyKay in forum Newbie
    Replies: 3
    Last Post: 30th March 2014, 16:23
  2. Replies: 9
    Last Post: 2nd April 2013, 10:02
  3. How do I set a QTextEdit to a specific line by line number?
    By Coolname007 in forum Qt Programming
    Replies: 8
    Last Post: 1st February 2013, 06:18
  4. [QTextEdit] Delete single lines
    By bmn in forum Qt Programming
    Replies: 3
    Last Post: 18th July 2012, 17:57
  5. Modifying a line in a QTextEdit
    By elcuco in forum Qt Programming
    Replies: 1
    Last Post: 15th March 2008, 17:50

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.