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. Designate QTextBlock as "Heading 1"

Designate QTextBlock as "Heading 1"

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.1k Views 3 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.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    I build a QTextDocument by code using QTextCursor, and then export it to file in open document format. So far, so good, I can see my text and formats (font size, etc.).

    However, I'd like to designate a text block as "Heading 1", "Heading 2", etc., so that the user can later on easily create a table of contents from my exported document, in the word processing program of their choice.

    Is that possible, and if so, how?

    raven-worxR 1 Reply Last reply
    0
    • artwawA Offline
      artwawA Offline
      artwaw
      wrote on last edited by
      #2

      Hi,
      as far as I know QTextBlock has its own int number so it would be possible to add a string of your own and then QTextBlock::blockNumber().
      However there is no QString identifier in the QTextBlock itself that I know of.

      For more information please re-read.

      Kind Regards,
      Artur

      A 1 Reply Last reply
      0
      • artwawA artwaw

        Hi,
        as far as I know QTextBlock has its own int number so it would be possible to add a string of your own and then QTextBlock::blockNumber().
        However there is no QString identifier in the QTextBlock itself that I know of.

        A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        @artwaw
        Docs on blockNumber: "Note that this function only makes sense in documents without complex objects such as tables or frames."
        Also, it doesn't seem to have a set method, so I guess the number is automatically determined in some way.

        artwawA 1 Reply Last reply
        0
        • A Asperamanca

          @artwaw
          Docs on blockNumber: "Note that this function only makes sense in documents without complex objects such as tables or frames."
          Also, it doesn't seem to have a set method, so I guess the number is automatically determined in some way.

          artwawA Offline
          artwawA Offline
          artwaw
          wrote on last edited by
          #4

          @Asperamanca It is just zero-based index count of all the blocks in the QTextDocument.

          For more information please re-read.

          Kind Regards,
          Artur

          1 Reply Last reply
          0
          • A Asperamanca

            I build a QTextDocument by code using QTextCursor, and then export it to file in open document format. So far, so good, I can see my text and formats (font size, etc.).

            However, I'd like to designate a text block as "Heading 1", "Heading 2", etc., so that the user can later on easily create a table of contents from my exported document, in the word processing program of their choice.

            Is that possible, and if so, how?

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by raven-worx
            #5

            @Asperamanca
            QTextBlock derives QTextFormat. QTextFormat can store user properties (see QTextFormat::setProperty())
            You just need to define an enum with your custom property ids for example:

            enum PropertyId {
                 Heading1PropertyId = QTextFormat::UserProperty+1000
            };
            ...
            textBlock.setProperty(Heading1PropertyId, QVariant::fromValue<bool>(true));
            textBlock.boolProperty(Heading1PropertyId); // convenience getter
            

            --- 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

            1 Reply Last reply
            3

            • Login

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