Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Changing QTextBlock behavior for a QTextDocument
Forum Updated to NodeBB v4.3 + New Features

Changing QTextBlock behavior for a QTextDocument

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 959 Views 1 Watching
  • 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 Offline
    L Offline
    lzrdkng
    wrote on 13 Jul 2017, 19:00 last edited by
    #1

    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?

    R 1 Reply Last reply 14 Jul 2017, 08:07
    0
    • L lzrdkng
      13 Jul 2017, 19:00

      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?

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 14 Jul 2017, 08:07 last edited by
      #2

      @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 15 Jul 2017, 12:32
      2
      • R raven-worx
        14 Jul 2017, 08:07

        @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();
        }
        
        L Offline
        L Offline
        lzrdkng
        wrote on 15 Jul 2017, 12:32 last edited by
        #3

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

        1 Reply Last reply
        0

        2/3

        14 Jul 2017, 08:07

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved