Results 1 to 1 of 1

Thread: QTextCursor manipulation truncates my text content in QTextEdit !?!?!

  1. #1
    Join Date
    Oct 2013
    Location
    Vienna / Austria
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTextCursor manipulation truncates my text content in QTextEdit !?!?!

    Dear colleagues,
    does anybody know about limits of text content in QTextEdit or QTextBrowser?
    I would like to show 500k of text (5000 lines of 100chars per line) to the user and do some simple content manipulation (like inserting some snippets or set background colors for specific words). But as soon as this kind of adaption occurs, my text will be truncated to 154 lines.
    Has anybody seen this before?

    Env: Qt5.1.1, Win8, VS2012

    Here is a small code to reproduce this anomaly.

    Qt Code:
    1. // create the UI
    2. QDialog *dial = new QDialog;
    3. dial->resize(400, 300);
    4. QVBoxLayout *vbl = new QVBoxLayout(dial);
    5. QTextEdit* edit = new QTextEdit();
    6. vbl->addWidget(edit);
    7. edit->setLineWrapMode(QTextEdit::NoWrap);
    8. edit->setAcceptRichText(false);
    9. dial->setLayout(vbl);
    10. dial->show ();
    11.  
    12. // add some content text
    13. for (int i=0; i<5000; i++)
    14. s += QString::number(i) + ": " + QString('x',120) + "\n";
    15. edit->setPlainText (s);
    16.  
    17. // now lets manipulate the text. e.g. prepand "Start"
    18. QTextCursor cursor = edit->textCursor();
    19. cursor.movePosition(QTextCursor::Start);
    20. cursor.insertText ("Start: "); // this command truncates the content to 154 lines
    21. // if you comment this out, the whole content will be shown
    To copy to clipboard, switch view to plain text mode 

    Thank you in advance.
    Regards, Thomas


    Added after 42 minutes:


    I found in another question the source of the problem.
    edit->setPlainText (and I think also the other variants) does it's job in parts of text in a kind of background tasks. Therefore I see only the first chunk of text.
    When I add a QApplication:rocessEvents (QEventLoop::AllEvents, 2000); it shows the complete text. It's only a workaround and not a real solution. A better way would be to do manipulation after a "finished" signal from the QTextEdit. But I don't see one. I only found "textChanged" and I think this will be fired with every little changing and not only by this initial setting.
    Do you have any other idea?
    Best regards,
    Thomas
    Last edited by Thomas G2; 18th October 2013 at 13:03.

Similar Threads

  1. QTextCursor / replace selected text
    By migel in forum Newbie
    Replies: 3
    Last Post: 24th December 2012, 15:06
  2. QTextEdit QTextCursor and a initial blank space
    By kuku83 in forum Qt Programming
    Replies: 0
    Last Post: 22nd October 2012, 17:10
  3. Text Manipulation.
    By suneel1310 in forum Qt Programming
    Replies: 7
    Last Post: 26th July 2010, 10:07
  4. Replies: 1
    Last Post: 11th April 2009, 22:27
  5. QTextEdit,QTextDocument,QTextCursor
    By kemp in forum Qt Programming
    Replies: 3
    Last Post: 13th October 2006, 12:03

Tags for this Thread

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.