QPushButton becomes invisible on hover event - opacity animation

  • Hey everyone,
    This is the solution that worked for me while facing a mysterious issue (bug) today, hope it helps someone.
    I have a QWidget (subclass) with some QPushButtons in it (without layout). This widget is shown if it's hovered, and an opacity animation accompanies the display. And when it's shown you can press (or whatever...) the QPushButtons we have already talked about.
    Here is a code snippet:

    void widget::OpaShow
          QGraphicsOpacityEffect *opacity = new QGraphicsOpacityEffect;
          QPropertyAnimation *anim = new QPropertyAnimation( opacity, "opacity" );

    The problem occurred with msvc2015 compiler, (mingw is an easy guy). The QPushButtons inside my widget becomes invisible when I hover them, voilĂ  :

    I still don't know why is that happening, it's a kind of bug I think.
    So the solution is to call deleteLater() for QGraphicsOpacityEffect object created, by adding this line to widget::OpaShow :

       connect(anim, SIGNAL(finished()), opacity, SLOT(deleteLater()));

    So the rendering will work as expected, and like it worked already on mingw

    Have a nice day :)

Log in to reply