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. List <ul> in QTextBrowser doesn't end
Forum Updated to NodeBB v4.3 + New Features

List <ul> in QTextBrowser doesn't end

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 2.9k 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.
  • P Offline
    P Offline
    Pippin
    wrote on last edited by
    #1

    Hello,

    my code is like

    QString newEntry = "<b>Some stuff, and now here's a list:</b><ul>"
    
    for (auto k : container)
    {
        // ...
        newEntry += ("<li><b>" + /* other things that are not breaking <li> or <b> */ + "</b></li>");
        // ...
    }
    
    newEntry += "</ul>";
    myQTextBrowser->append(newEntry);
    

    Unfortunately, after newEntry got appended, any further appending would result in adding another item to the list, which I did end with </ul>. Replacing newEntry += "</ul>"; with newEntry += "</ul></ul>"; doesn't change anything, in case anyone would try that.

    Any input? Thanks in advance!

    jsulmJ 1 Reply Last reply
    0
    • P Pippin

      Hello,

      my code is like

      QString newEntry = "<b>Some stuff, and now here's a list:</b><ul>"
      
      for (auto k : container)
      {
          // ...
          newEntry += ("<li><b>" + /* other things that are not breaking <li> or <b> */ + "</b></li>");
          // ...
      }
      
      newEntry += "</ul>";
      myQTextBrowser->append(newEntry);
      

      Unfortunately, after newEntry got appended, any further appending would result in adding another item to the list, which I did end with </ul>. Replacing newEntry += "</ul>"; with newEntry += "</ul></ul>"; doesn't change anything, in case anyone would try that.

      Any input? Thanks in advance!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Pippin Then remove </ul> from myQTextBrowser before appending again

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Pippin Then remove </ul> from myQTextBrowser before appending again

        P Offline
        P Offline
        Pippin
        wrote on last edited by
        #3

        @jsulm If I do that, the text isn't processed at all. All tags are printed as though they were normal text.

        jsulmJ 1 Reply Last reply
        0
        • P Pippin

          @jsulm If I do that, the text isn't processed at all. All tags are printed as though they were normal text.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Pippin Maybe you should get the whole text from the text browser, remove </ul>, append new list entries with </ul> at the end and then set the text in text browser?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Pippin
            wrote on last edited by Pippin
            #5

            So I used QTextBrowser::toHtml to get the text, and this is what is processed:

            <ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;">
            <li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">foo</li>
            <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">foo</li>
            <li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">foo</li></ul></body></html>
            

            (I added one linebreak so that it's easier to read.)

            So the </ul> tag is definitely here, but next time I append something, it is removed and added at the very end of the body. I really don't understand because there's only 1 member function that I have that toys with </ul>. Here's what the text looks like after the next appending:

            <ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;">
            <li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">foo</li>
            <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">foo</li>
            <li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">foo</li>
            <li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">foo</li></ul></body></html>
            
            jsulmJ 1 Reply Last reply
            0
            • P Pippin

              So I used QTextBrowser::toHtml to get the text, and this is what is processed:

              <ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;">
              <li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">foo</li>
              <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">foo</li>
              <li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">foo</li></ul></body></html>
              

              (I added one linebreak so that it's easier to read.)

              So the </ul> tag is definitely here, but next time I append something, it is removed and added at the very end of the body. I really don't understand because there's only 1 member function that I have that toys with </ul>. Here's what the text looks like after the next appending:

              <ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;">
              <li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">foo</li>
              <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">foo</li>
              <li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">foo</li>
              <li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">foo</li></ul></body></html>
              
              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Pippin It looks good. But text browser shows HTML, or what is the problem?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Pippin
                wrote on last edited by Pippin
                #7

                It just seems that I can't close the list with </ul>. Whether I add the tag at the end of newEntry, or append it alone after newEntry, it's as if it was always ignored.

                Are there other closing tags that I could try? Hopefully some "stronger" than </ul>.

                Solved: Or is it? I just dropped the idea of using <ul> and constructed my own syntax with <br>&nbsp;&nbsp;&nbsp;&nbsp;&#9899; :-)

                1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #8

                  The problem is with append() from the docs:

                  Note: The new paragraph appended will have the same character format and block format as the current paragraph, determined by the position of the cursor.

                  So it will try and maintain the list you are currently in

                  you should really use the text cursor interface to edit the document:

                  replace myQTextBrowser->append(newEntry); with

                  QTextCursor cursor=myQTextBrowser->textCursor();
                  cursor.insertBlock();
                  cursor.insertHtml(newEntry);
                  

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  1 Reply Last reply
                  1

                  • Login

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