Results 1 to 10 of 10

Thread: How to animate the transparency of a child QPushButton using QPropertyAnimation ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    3
    Qt products
    Qt Jambi
    Platforms
    Unix/X11

    Default How to animate the transparency of a child QPushButton using QPropertyAnimation ?

    I want to progressively decrease the opacity of a QPushButton over a time of 2 seconds to complete transparency. For that I used the QPropertyAnimation class and used the property "windowOpacity" of the button to achieve the effect. But that worked only for a standalone QPushButton. When I assigned a parent to the button, the effect disappeared. Is there any way of achieving the same effect for child buttons ?

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to animate the transparency of a child QPushButton using QPropertyAnimation ?

    This is the side effect of child widgets not being windows in Qt.
    You can only do the opacity on the parent.

    edit: however, this doesn't mean it is impossible.
    Use a style specific for your button.
    Last edited by tbscope; 17th October 2010 at 18:31.

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

    daudiam (17th October 2010)

  4. #3
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    3
    Qt products
    Qt Jambi
    Platforms
    Unix/X11

    Default Re: How to animate the transparency of a child QPushButton using QPropertyAnimation ?

    Thanks. But how do we specify transparency levels in buttons ? I mean, any functions, any property which I can set.

  5. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to animate the transparency of a child QPushButton using QPropertyAnimation ?

    Read about QPalette.

  6. #5
    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: How to animate the transparency of a child QPushButton using QPropertyAnimation ?

    Let's try to go for a quick solution. Subclass QPushButton, add a qreal "opacity" property to the button subclass (so that you can animate its value) and reimplement the paint event. In the event implementation there are two things that might work. First you might try setting up a painter and calling QPainter::setOpacity() before calling the base class implementation or if this doesn't work, call the base class implementation first and then use QPainter::setCompositionMode() to setup a composition mode that will allow you to paint the alpha channel to what is already painted using an opacity of your choice. Which composition mode to choose is left as an exercise to the reader.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QPropertyAnimation and animation speed
    By themk in forum Qt Programming
    Replies: 0
    Last Post: 13th October 2010, 00:05
  2. QPropertyAnimation and QStackedLayout:functionality.
    By savaliya_ambani in forum Qt for Embedded and Mobile
    Replies: 11
    Last Post: 24th September 2010, 08:33
  3. Using QPropertyAnimation with QGraphicsPixmapItem
    By Luc4 in forum Qt Programming
    Replies: 8
    Last Post: 29th March 2010, 09:47
  4. Replies: 1
    Last Post: 8th January 2010, 12:21
  5. Replies: 2
    Last Post: 11th November 2009, 08:03

Tags for this Thread

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.