[Qt-interest] Painting Behind a QTextEdit

Tony Rietwyk tony.rietwyk at rightsoft.com.au
Sat Jul 24 04:18:45 CEST 2010


Hi Jordan, 
 
I'm confused - does rect() cover the whole client area?  What's the point of
making the palette transparent, if you are going to draw over the widget
anyway?   Why not use the inherited QFrame properties to draw your white
border?  
 
Tony
 

-----Original Message-----

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/20100724/615f18bc/attachment.html 


More information about the Qt-interest-old mailing list