plasma::applet painter

Aaron J. Seigo aseigo at kde.org
Sat Feb 21 17:34:27 CET 2009


On Saturday 21 February 2009, Toussis Manolis wrote:
> I want to add some effect to an applet

what effect are you trying to achieve? because while you ask how to get a 
pixmap of your widget, depending on what effect you are trying to achieve that 
may not be what you actually want to be doing.

> QPixmap* m_oldPixmap;
>
> void PlasmaApplet::paintInterface(QPainter *p,
>         const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
> {
>    .... do the painting....
>   and now:
>   store the current image of the applet for future use in a QPixmap/QImage
>  something like that:
>   m_oldPixmap=new QPixmap(PlasmaApplet::pixmap())
> };
>
>
> any ideas?

to answer the question you asked, though:

inside of paintInterface, paint everything onto a pixmap and then blit that 
pixmap using the QPainter passed in as the final step, e.g. something like 
this semi-pseudocode:

if (m_oldPixmap->size() != size()) {
    delete m_oldPixmap;
    m_oldPixmap = new QPixmap(size());
    m_oldPixmap->fill(QColor(Qt::transparent));
}

QPainter painter(m_oldPixmap);
... do the painting ...
painter.end();
p->drawPixmap(option->rect, m_oldPixmap, option->rect);

-- 
Aaron J. Seigo
humru othro a kohnu se
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA  EE75 D6B7 2EB1 A7F1 DB43

KDE core developer sponsored by Qt Software

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://mail.kde.org/pipermail/plasma-devel/attachments/20090221/4ed43738/attachment.sig 


More information about the Plasma-devel mailing list