[Qt-interest] QWebView inactive highlighted text color background

Strahinja Markovic strahinja.markovic at gmail.com
Fri Nov 20 22:35:04 CET 2009


Strahinja Markovic wrote:

> Hi,
> 
> I was wondering what would be the best way to change the background color
> of the selected text highlight in QWebView when the window is inactive?
> 
> Let me elaborate...
> 
> I'm using a (sub-classed) QWebView as a WYSIWYG editor component, and I've
> now mostly implemented a find&replace dialog. Now the dialog is a
> separate, non-modal window that can control the QWebView. I have managed
> to successfully select the searched-for text with JavaScript, but since
> the QWebView is in a separate window which is inactive, the text is
> highlighted in a very light gray color. It's barely distinguishable from
> the white background.
> 
> Now if I switch the focus back to the main window, the highlight is that
> nice blue color again. But I don't want the main window to have focus. I
> want the find&replace dialog to keep it so the user can continue pressing
> <Enter> with the "Find Next" button selected.
> 
> So I'm wondering how I could change that inactive selected text background
> color. I've already tried using a custom QPalette, but QWebView ignores
> this. I've read this can happen.
> 
> I was thinking of getting the size of the dimensions of the highlighted
> rectangle and painting over that, but I don't know how to get those
> dimensions. It also seems like overkill, but I'd be willing to try it.
> 
> I know I could do this by temporarily changing the underlying HTML and
> inserting some highlighting CSS + <span>, but that's the last thing I'm
> willing to try. I _really_ don't want to mess with the user's code.
> 
> Does anyone have any ideas?
> 
> Thanks in advance,
> 
> Strahinja Markovic

For the sake of posterity, this can be solved by setting a custom QPalette 
globally, with QApplication::setPalette(). For some reason, QWebView ignores
the palette that is set directly on it.

I've reported this bug on the WebKit bug tracker: 
https://bugs.webkit.org/show_bug.cgi?id=31742

More information (and example code) can be found in the bug report. 

-- 

Sincerely,

Strahinja Markovic



More information about the Qt-interest-old mailing list