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. How to mark text as a header in QTextEdit
QtWS25 Last Chance

How to mark text as a header in QTextEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 505 Views
  • 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.
  • C Offline
    C Offline
    clarify
    wrote on last edited by
    #1

    QTextEdit has the ability to read and generate HTML, but I wonder how can I tell it in my code what part of the current document should be a header, or the equivalent for instance of an H1 or H2 tag?
    I assume I'd need to set the paragraph style for the selected paragraph however the only API call that I see is setAlignment.

    SGaistS 1 Reply Last reply
    0
    • C clarify

      QTextEdit has the ability to read and generate HTML, but I wonder how can I tell it in my code what part of the current document should be a header, or the equivalent for instance of an H1 or H2 tag?
      I assume I'd need to set the paragraph style for the selected paragraph however the only API call that I see is setAlignment.

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      QTextDocument is the core interface for that.

      Take a look a the Text Edit example. It should give you some nice pointers.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      C 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        QTextDocument is the core interface for that.

        Take a look a the Text Edit example. It should give you some nice pointers.

        C Offline
        C Offline
        clarify
        wrote on last edited by
        #3

        @SGaist
        Thanks that helped. I have a new problem now though:

        QTextBlockFormat's ident function returns what appear to be incorrect values.

        If I pass in HTML, and the text is indented, the indent() method will return 0 even for indented text.

        JonBJ 1 Reply Last reply
        0
        • C clarify

          @SGaist
          Thanks that helped. I have a new problem now though:

          QTextBlockFormat's ident function returns what appear to be incorrect values.

          If I pass in HTML, and the text is indented, the indent() method will return 0 even for indented text.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @clarify
          Text is indented how in your HTML? Minimal example please.

          C 1 Reply Last reply
          0
          • JonBJ JonB

            @clarify
            Text is indented how in your HTML? Minimal example please.

            C Offline
            C Offline
            clarify
            wrote on last edited by
            #5

            @JonB
            <html><body>
            <div style="margin-left:30px;">indented</div>

            JonBJ 1 Reply Last reply
            0
            • C clarify

              @JonB
              <html><body>
              <div style="margin-left:30px;">indented</div>

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @clarify
              Did you check what QTextBlockFormat::leftMargin() returns?

              C 1 Reply Last reply
              0
              • JonBJ JonB

                @clarify
                Did you check what QTextBlockFormat::leftMargin() returns?

                C Offline
                C Offline
                clarify
                wrote on last edited by clarify
                #7

                @JonB said in How to mark text as a header in QTextEdit:

                leftMargin

                Oh I was assuming Qt infers the indentation from the left margin value.

                Is there a better way using HTML to tell QTextEdit what the indentation level is?

                The style text-indent does intent as well, but the indent() method still returns 0.

                I tried using <dl><dd> but these didn't cause any indentation at all.
                It's the same with <ol>.

                By the way, just a feature request: It'd be nice if QTextEdit could generate simple HTML, with no CSS at all, like the more rudimentary browsers can understand e.g. Lynx, Links.

                JonBJ 1 Reply Last reply
                0
                • C clarify

                  @JonB said in How to mark text as a header in QTextEdit:

                  leftMargin

                  Oh I was assuming Qt infers the indentation from the left margin value.

                  Is there a better way using HTML to tell QTextEdit what the indentation level is?

                  The style text-indent does intent as well, but the indent() method still returns 0.

                  I tried using <dl><dd> but these didn't cause any indentation at all.
                  It's the same with <ol>.

                  By the way, just a feature request: It'd be nice if QTextEdit could generate simple HTML, with no CSS at all, like the more rudimentary browsers can understand e.g. Lynx, Links.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @clarify
                  Glancing at sources I can only say/see that QTextEdit sets indent in QTextEditPrivate::createAutoBulletList(). For the rest there is a QTextHtmlImporter::import(). For yours maybe you'd have more luck with <ul>, I don't know.

                  By the way, just a feature request: It'd be nice if QTextEdit could generate simple HTML, with no CSS at all, like the more rudimentary browsers can understand e.g. Lynx, Links.

                  By now you should know this a user forum, and I am a user just like you, no point requesting features here!

                  1 Reply Last reply
                  0
                  • JonBJ JonB referenced this topic on

                  • Login

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