0

In an application I'm building I'm displaying some HTML using QTextBrowser. The HTML contains some nested lists, and I'm finding that the last parent item has some extra white space between it and its first child list item.

Simplified example:

list.html:

<ul>
    <li>Parent List A
        <ul>
            <li>A1</li>
            <li>A2</li>
        </ul>
    </li>
    <li>Parent List B
        <ul>
            <li>B1</li>
            <li>B2</li>
        </ul>
    </li>
</ul>

list_test.py:

import sys
from PySide2.QtWidgets import QApplication, QTextBrowser

with open('./list.html') as f:
    html = f.read()

app = QApplication()

text_widget = QTextBrowser()
text_widget.setHtml(html)
text_widget.show()

sys.exit(app.exec_())

produces a widget that looks like this:

enter image description here

What's also odd is that it's only ever the last item of the parent list. So, if I add a Parent List C:

list.html:

<ul>
    <li>Parent List A
        <ul>
            <li>A1</li>
            <li>A2</li>
        </ul>
    </li>
    <li>Parent List B
        <ul>
            <li>B1</li>
            <li>B2</li>
        </ul>
    </li>
    <li>Parent List C
        <ul>
            <li>C1</li>
            <li>C2</li>
        </ul>
    </li>
</ul>

it's only that Parent List C that shows this extra white space:

enter image description here

I'm testing this on Windows 10 with PySide2 version 5.11.0

dan_g
  • 2,712
  • 5
  • 25
  • 44
  • Seems related to [QTBUG-32084](https://bugreports.qt.io/browse/QTBUG-32084). – ekhumoro Jan 29 '19 at 17:43
  • Yeah I should have checked their issue tracker first. It was apparently reported several years ago in Qt4...apparently it was never fixed: [QTBUG-1586](https://bugreports.qt.io/browse/QTBUG-1586) – dan_g Jan 29 '19 at 18:10
  • There's no point trying to re-open an issue for qt4, since it's no longer supported. You need to open a new issue for qt5 (not pyside2). – ekhumoro Jan 29 '19 at 18:15
  • was just following what was suggested in the last comment on that issue, but yeah I'll go ahead and open a new one. – dan_g Jan 29 '19 at 18:17

1 Answers1

2

If you close the <li> tags before opening the <ul> there is no longer an issue with the display.

<ul>                                                              
    <li>Parent List A</li>    
        <ul>    
            <li>A1</li>    
            <li>A2</li>    
        </ul>    
    <li>Parent List B</li>                                        
        <ul>                                                      
            <li>B1</li>                                           
            <li>B2</li>                                           
        </ul>                                                     
</ul> 

I'm not currently working with HTML, but I have always used this approach, instead of leaving <li> open and placing an <ul> inside, so maybe if that's valid HTML. If your HTML is standard I would re-open the issue for Qt5.

cmaureir
  • 285
  • 2
  • 8
  • Yeah this is the current workaround I'm using. [This is not valid HTML though](https://stackoverflow.com/a/5899394/3014097), so I've opened a new issue on their tracker: [QTBUG-73436](https://bugreports.qt.io/browse/QTBUG-73436) – dan_g Jan 31 '19 at 15:51
  • Thanks for letting me know! hopefully the bug will be addressed soon ;) – cmaureir Jan 31 '19 at 15:57