Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Highlight text given a search string
QtWS25 Last Chance

Highlight text given a search string

Scheduled Pinned Locked Moved General and Desktop
qmodelindexqmodelindexlistqtableviewqstyleditemdelemodelviewqtdisplayroleqabstractdocumeqstyleoptionqtextdocument
2 Posts 2 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    frostbytes89
    wrote on last edited by
    #1

    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:
    http://stackoverflow.com/questions/30520865/highlight-text-that-matches-a-search-string-in-qt5

    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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved