Hi,

I'm trying to implement a search feature much like Google Chrome has, where keywords found are highlighted in the document, and the vertical scrollbar is decorated with very thin lines, corresponding to the entire height of the document. I found this feature to be quite nice, and would like to put it inside my application as well

I've been trying many different ways to easily scale an item into the proper position on the scrollbar, so that a line can be drawn across its width (indicating the location of a found keyword). Here is an example picture for those who haven't used Google Chrome yet:



Anyway, my current method of attack to this problem is to get the full height of the document using QPlainTextEdit::cursorRect() (putting the cursor at the bottom), getting the partial height of the currently found keyword using the same method, getting a ratio of partialHeight / fullHeight, and then multiplying that ratio by the height of the scrollbar in order to find the position to draw the line. However, this isn't working too well. It seems as though the Y coordinate returned from cursorRect() is dependent on the size of the viewport (if I make it longer, then the Y coord returned is greater).

So, basically, I'm wondering a couple things:

1) Is there some special secret to viewport coordinates I don't know about? I currently have little understanding of them, and can't find anything about them in the docs.

2) Is there a better way of doing what I'm trying to do? As a backup solution, I'm considering using QPlainTextEdit::blockCount() and QTextCursor::blockNumber() and taking the ratio of blockNum / blockCount and using that to get the position in the scrollbar, but that will be far less accurate, because i have several blocks that have multiple lines in them.


Thanks,
Sean