Link to project's GitHub

I am attempting to make an instant-as-you-type-file-search for linux inspired by Everything-search-engine.
It's in PyQt5 and Python3. Week ago I got it in to pretty decent shape by my standard:



Now for the last few days I was attempting to get the search term to appear bold in the results in the listview and for that I had to use delegate so that I can just use bold tags.
I struggled through and got it somewhat working, without some decent understanding of how it works as I have not found much tutorial resources on the delegates in PyQt/PySide, just completed done things that I could observe and tinker around with.

Now when its relatively done I observed visual degradation in quality when compared to the version without a delegate.

Heres a gif of it in action showing first with the delegate and then without

gfycat backup link

I would describe it that the listview seems to have multiple empty frames where it shows nothing before content appears, which make it look like its its blinking.
This does not appear when not using the delegate.


Here is the code of the delegate in question:

Qt Code:
  1. class HTMLDelegate(QStyledItemDelegate):
  2. def paint(self, painter, option, index):
  3. options = QStyleOptionViewItem(option)
  4. self.initStyleOption(options, index)
  5. style = QApplication.style() if options.widget is None \
  6. else options.widget.style()
  7.  
  8. doc = QTextDocument(self)
  9. doc.setHtml(options.text)
  10.  
  11. options.text = ""
  12. style.drawControl(QStyle.CE_ItemViewItem, options, painter)
  13.  
  14. ctx = QAbstractTextDocumentLayout.PaintContext()
  15.  
  16. if option.state & QStyle.State_Selected:
  17. ctx.palette.setColor(QPalette.Text, option.palette.color(
  18. QPalette.Active, QPalette.HighlightedText))
  19.  
  20. textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
  21. painter.save()
  22. painter.translate(textRect.topLeft())
  23. painter.setClipRect(textRect.translated(-textRect.topLeft()))
  24. doc.documentLayout().draw(painter, ctx)
  25.  
  26. painter.restore()
  27.  
  28. def sizeHint(self, option, index):
  29. options = QStyleOptionViewItem(option)
  30. self.initStyleOption(options, index)
  31.  
  32. doc = QTextDocument(self)
  33. doc.setDocumentMargin(1)
  34. doc.setHtml(options.text)
  35. return QSize(doc.idealWidth(), 23)
To copy to clipboard, switch view to plain text mode 

Is this solvable? Or is it the performance price for using custom delegate and theres just no way around it?