0

I am writing a PySide2 application, I have a QTableWidget in it filled almost totally with QTableWidgetItem objects.

I would like to highlight several parts of text inside the QTableWidgetItems, I tried to setText("<b>hello</b>") but I see it is not rendered, it appears verbatim.

Is there some way to do it or do I need to change QTableWidgetItem with some other widget ?

Nicola Mingotti
  • 860
  • 6
  • 15
  • 1
    `QTableWidgetItem` cannot show html Text as it is. Rather, it shows just the HTML text. You must implement `StyledItemDelegate` and make it show HTML strings.This question is already, please look here[ https://stackoverflow.com/questions/1956542/how-to-make-item-view-render-rich-html-text-in-qt] – Haru Jan 24 '20 at 00:52
  • 1
    In the following links there are PyQt5 translations of that code so it will not be complicated to use it in PySide2 https://stackoverflow.com/questions/47890913/qt-designer-multiple-fonts-in-one-line-of-a-qlistwidget/47892504#47892504 and https://stackoverflow.com/questions/53569768/how-to-display-partially-bold-text-in-qlistwidgetitem-with-qtcore-qt-userrole/53572278#53572278 – eyllanesc Jan 24 '20 at 00:57
  • Thank you both. I am new to Qt. Since it is years people is asking this feature why isn't it implemented as a simple flag? Are there going to be dramatic slowdown in using the 'Delegate' way? Or maybe other inconviniences I shuold know of? – Nicola Mingotti Jan 24 '20 at 01:05
  • @NicolaMingotti I do not want changes in the Qt Widgets since it is a mature library that in recent years has only been polished in the bugs of the previous features. Maybe in Qt6 I could drive those changes even if I doubt it. The company has turned to optimize QML where what you want is very simple although it is the same solution: use a delegate. – eyllanesc Jan 24 '20 at 01:31

0 Answers0