Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Changing QTextBlock behavior for a QTextDocument

    General and Desktop
    2
    3
    674
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      lzrdkng last edited by

      The documentation says that a QTextDocument is compose of QTextBlock.
      Every QTextBlock is determine by a sequence of characters ending by the special character \n.

      But I can't seem to find how exactly it would be possible to change this behavior.
      For instance, I would like to define a QTextBlock as "one or more consecutive lines of text, separated by one or more blank lines", just like Markdown paragraph.

      Is there way to change the behavior of a QTextDocument so it produces QTextBlock the way I want?

      raven-worx 1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @lzrdkng last edited by

        @lzrdkng
        you are talking about the toPlainText() method right?

        A possibility is to traverse the QTextDocument yourself and generate the string (QTextBlock::text()) and insert your custom block separators.

        Untested:

        QString text;
        QTextBlock block = textDoc->firstBlock();
        while( block.isValid() )
        {
             text.append( block.text() );
             text.append( MY_SEPARATOR_STRING );
             block = block.next();
        }
        

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        L 1 Reply Last reply Reply Quote 2
        • L
          lzrdkng @raven-worx last edited by

          @raven-worx Thank for the idea! I'll dig into it!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post