Results 1 to 8 of 8

Thread: Fading effect on QPainter fillrect()

  1. #1
    Join Date
    Apr 2008
    Posts
    37
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Fading effect on QPainter fillrect()

    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

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Fading effect on QPainter fillrect()

    I guess this will help you

  3. The following user says thank you to aamer4yu for this useful post:

    smarinr (29th April 2008)

  4. #3
    Join Date
    Apr 2008
    Posts
    37
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Fading effect on QPainter fillrect()

    let me show you my code:

    Qt Code:
    1. void QtProfileBar::paintEvent(QPaintEvent * event) {
    2.  
    3. if (_currentLabel) {
    4. QRect r = rect();
    5. QPixmap pixmap(SOMETHING FOR THE PIXMAP);
    6. QBrush brush(pixmap);
    7. QPainter painter(this);
    8. painter.fillRect(r, brush);
    9. painter.end();
    10. } else {
    11. QWidget::paintEvent(event);
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    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
    Last edited by jpn; 29th April 2008 at 19:46. Reason: missing [code] tags

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Fading effect on QPainter fillrect()

    Oh... you probably mean a gradient? Take a look at QLinearGradient.

  6. The following user says thank you to wysota for this useful post:

    smarinr (29th April 2008)

  7. #5
    Join Date
    Apr 2008
    Posts
    37
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Fading effect on QPainter fillrect()

    no Gradient... let me think how I can show you more exactly what am I doing

  8. #6
    Join Date
    Apr 2008
    Posts
    37
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Fading effect on QPainter fillrect()

    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...

  9. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Fading effect on QPainter fillrect()

    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.
    J-P Nurmi

  10. The following user says thank you to jpn for this useful post:

    smarinr (29th April 2008)

  11. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Fading effect on QPainter fillrect()

    But you will still need to animate the fade yourself using some timer. Read this:
    http://doc.trolltech.com/qq/qq16-fader.html

  12. The following user says thank you to wysota for this useful post:

    smarinr (29th April 2008)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.