[Qt-interest] Painting Behind a QTextEdit

Jordan Upham jupham at zipitwireless.com
Fri Jul 23 20:16:18 CEST 2010


I am trying to paint a custom frame behind a QTextEdit but I cannot get the
painter to activate.  What I want to do is have the QTextEdit be transparent
except for the text and scroll bars allowing me to paint behind it but I'm
not sure why the painter won't activate.  Here is what I am trying.

MyTextEdit::MyTextEdit(QWidget *parent) : QTextEdit(parent)
{
    /* Set Base Transparent */
    setFrameStyle(QFrame::NoFrame);
    QPalette pal = palette();
    pal.setBrush(QPalette::Base, Qt::transparent);
    pal.setBrush(QPalette::Text, Qt::black);
    setPalette(pal);
}

void MyTextEdit::paintEvent(QPaintEvent *event)
{
    /* Draw custom frame (black with 2px white border) */
    QPainter painter(this);
    painter.fillRect(rect(), Qt::black);
    painter.setPen(QPen(Qt::white, 2));
    painter.drawRect(rect());

    /* Call Text Edit Paint Event to draw text edit */
    QTextEdit::paintEvent(event);
}

I've done similar things with other widgets and it works fine.  Any help is
appreciated.

Thanks,
Jordan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100723/e229090a/attachment.html 


More information about the Qt-interest-old mailing list