Search code examples
pythoncsspyside2qtextbrowser

How to set bottom border using css in QTextBrowser?


Suppose I have a QT window (using Pyside2, like PyQT5) with the following widget:

import sys

from PySide2.QtWidgets import QApplication, QMainWindow, QTextBrowser

app = QApplication(sys.argv)

main_window = QMainWindow()
html_string = """
<style>
td { border-bottom: 1px solid #000000; color: blue }
</style>
<table>
  <tr>
    <td>1</td>
    <td>2</td>
  </tr>
  <tr>
    <td>3</td>
    <td>4</td>
  </tr>
</table>
"""
text_browser = QTextBrowser()
text_browser.setHtml(html_string)
text_browser.setReadOnly(True)

main_window.setCentralWidget(text_browser)

main_window.show()

exit_code = app.exec_()
sys.exit(exit_code)

I expect the widget to display the table with bottom borders. Something like this:

expected

(image: table with bottom borders).

But I get this:

actual

(image: table without borders).

The documentation suggests however that border styles using css are supported on table cells.

  • Note: that using inline style like <td style="border-bottom: 1px solid #000000"> makes no difference.
  • Note2: I'm only trying to have a bottom border, so setting <table border="1"> does not give a desirable result.

Does anyone have an idea on whether this can be achieved at all, and if so, how?


Solution

  • To answer my own question:

    I used PySide2-5.13.0 with shiboken2-5.13.0. After updating them both to 5.14.0 it now works as expected.