[Qt-interest] Painting Behind a QTextEdit

Diego Iastrubni diegoiast at gmail.com
Sat Jul 24 02:30:31 CEST 2010


QTextEdit is a very complex widget. It inherits QScrollWidget which means
the real stuff is done inside the viewport() which is IMHO, why you painting
is not taking effect.

Just a thought: can you do this with CSS maybe...?

On Fri, Jul 23, 2010 at 9:16 PM, Jordan Upham <jupham at zipitwireless.com>wrote:

> 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
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100724/4ef65df7/attachment.html 


More information about the Qt-interest-old mailing list