List <ul> in QTextBrowser doesn't end
-
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
newEntrygot appended, any further appending would result in adding another item to the list, which I did end with</ul>. ReplacingnewEntry += "</ul>";withnewEntry += "</ul></ul>";doesn't change anything, in case anyone would try that.Any input? Thanks in advance!
-
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
newEntrygot appended, any further appending would result in adding another item to the list, which I did end with</ul>. ReplacingnewEntry += "</ul>";withnewEntry += "</ul></ul>";doesn't change anything, in case anyone would try that.Any input? Thanks in advance!
-
@jsulm If I do that, the text isn't processed at all. All tags are printed as though they were normal text.
-
So I used
QTextBrowser::toHtmlto 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> -
So I used
QTextBrowser::toHtmlto 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> -
It just seems that I can't close the list with
</ul>. Whether I add the tag at the end ofnewEntry, or append it alone afternewEntry, 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> ⚫:-) -
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);withQTextCursor cursor=myQTextBrowser->textCursor(); cursor.insertBlock(); cursor.insertHtml(newEntry);