PDA

View Full Version : Fading effect on QPainter fillrect()



smarinr
28th April 2008, 21:18
Hi guys, I really need a little bit of help on this one

I need to make a QPainter fillrect have some animation but I can´t get it.

if someone know a very easy way to make this happen, please let me know

aamer4yu
28th April 2008, 21:36
I guess this (http://wiki.qtcentre.org/index.php?title=Fade_and_scroll_effects) will help you :)

smarinr
29th April 2008, 00:01
let me show you my code:


void QtProfileBar::paintEvent(QPaintEvent * event) {

if (_currentLabel) {
QRect r = rect();
QPixmap pixmap(SOMETHING FOR THE PIXMAP);
QBrush brush(pixmap);
QPainter painter(this);
painter.fillRect(r, brush);
painter.end();
} else {
QWidget::paintEvent(event);
}
}

I don´t understand too much about Qpixmap, QBRUSH or QPAINTER.. but this code frag is what show a profile bar when you click something

wysota
29th April 2008, 00:50
Oh... you probably mean a gradient? Take a look at QLinearGradient.

smarinr
29th April 2008, 01:06
no Gradient... let me think how I can show you more exactly what am I doing

smarinr
29th April 2008, 19:17
ok, here is what I need to do

you see that the code makes a QRect, take a QPixmap and put it on the QBrush and calls the QPainter to start painting fillRect()

that part is on the IF condition, but...
see the ELSE condition...
the part make a not good looking disappear of what we already paint...

so... in few words, my goal to achieve is that the ELSE dont make the rude changing on the UI, make it look like its disappearing little by little....

I dont know if someone understand that...

jpn
29th April 2008, 20:58
You can use QPainter::setOpacity(). You will have to make the opacity smoothly reduce from 1.0 to 0.0 instead of a "_currentLabel" flag which can only have two states.

wysota
29th April 2008, 22:57
But you will still need to animate the fade yourself using some timer. Read this:
http://doc.trolltech.com/qq/qq16-fader.html