[Qt-interest] Qt4.5.2 Painting an Overlay *under* a QTextEdit

Josh jnfo-c at grauman.com
Wed Jul 8 23:03:00 CEST 2009


Hello all,

I've successfully been able to create an overlay widget on top of a 
QTextEdit like so:

   //Overlay is a QWidget subclass with a custom paintEvent()
   overlay = new Overlay(viewport());
   overlay->setAutoFillBackground(false);
   overlay->show();
   overlay->raise();

I then paint in Overlay::paintEvent() and am able to draw on top of a 
QTextEdit. However, I'd really like the overlay to be *under* the 
QTextEdit, so that the text is on top of what I'm drawing in my overlay 
QWidget. I've tried all kinds of things to no avail. I can't simply call 
overlay->lower(), because the viewport() is its parent, not its sibling. I 
tried constructing the overlay on the viewport's parent like: overlay = 
new Overlay(viewport()->parent()), but that messes up scrolling (the 
overlay doesn't scroll with the QTextEdit). I tried creating another 
overlay under the first overlay and redirecting the paint events from the 
QTextEdit to the 2nd overlay, but I can't paint to the widget outsite of 
its paintEvent() function. I'd rather not paint to an intermediate pixmap 
and then paint to the 2nd overlay in its paintEvent() function for speed 
reasons of basically having to paint twice...

Any ideas of how to (simply?) paint *under* a QTextEdit? Thanks.

Josh



More information about the Qt-interest-old mailing list