Highlight text given a search string

  • I'm just going to link my stack overflow question here rather than type it all out again since it was quite a bit to explain. You can view it here:

    What I'm trying to do is, given the list of QModelIndexes returned from QAbstractItemModel::match, I want to highlight just the part of the Qt::DisplayRole that contains the string that was searched for. Read that stack overflow post as it thoroughly explains the problem. I wouldn't be asking here but it is important that I figure it out, and I've spent 4 days already of research, reading docs, reading Qt source, and asking in the Qt IRC.

    This is such a common feature that it seems like somebody would have figured it out by now, but it seems that is not the case. Any help would be greatly appreciated!

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What about painting a partially transparent rectangle over the part of the text that should be highlighted ? You could draw the text first and then the rectangle over.

    Hope it helps