[Qt-interest] Qt4.5.2 Painting an Overlay *under* a QTextEdit
Girish Ramakrishnan
girish at forwardbias.in
Thu Jul 9 09:06:19 CEST 2009
By definition, a child of viewport() will paint after the viewport has
painted, so your approach of making the overlay a child of viewport
won't work.
You can achieve an 'underlay' (if there is such a term :-) ), by
reimplementing paintEvent of the text edit:
void MyTextEdit::paintEvent(QPaintEvent *event)
{
// paint underlay
QTextEdit::paintEvent(event);
}
Girish
Josh wrote:
> 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