3

I want to highlight (or in general customise the formatting) of specific substrings appearing in a QTreeView in PyQt. To demonstrate what I mean, I have taken the example at PyQt4\examples\itemviews\dirview.pyw and manually added highlighting:

enter image description here

Here all instances of the substring 'as' are highlighted, but in general it might not be a pattern match, I may actually want to be very specific.

I know that this can be easily done to a QTextEdit as per this SO question, but that relied on moving around the textCursor which I don't believe exists for a QTreeView.

Can this be easily done?

Community
  • 1
  • 1
bdforbes
  • 1,486
  • 1
  • 13
  • 31
  • 2
    You need to use a delegate to display the text in your treeview. With a delegate you can define your own widget (containing a label, lineedit, etc.) displaying (and formatting) the data received from the model. Have a look at http://qt-project.org/doc/qt-4.8/model-view-programming.html#delegate-classes – BBRodriguez May 13 '14 at 08:50
  • 1
    There is ready solution: http://stackoverflow.com/a/5443112/1387438 – Marek R May 13 '14 at 10:16

0 Answers0