Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[Solved] QGraphicsEffect not working on children
So I am trying to fade out a widget that has 2 children in an QHBoxLayout.
I set the QGraphicsOpacityEffect on the widget and then use a QPropertyAnimation to run the fade.
It seems to work on one of the items in the widget (kind of) but not the rest.
Only tested in Linux so far but intend to try it on OSX tomorrow to see if there is a problem with linux.
The behavior I see is when the effect is applied to fade out the widget it fades only a QLabel image (of a close button) in the upper right corner. And it fades only part of that. It's like the children aren't inheriting the QGraphicsEffect like they are supposed to.
Anyway, the only way to make the rest of the widget draw correctly is to move the window. I've tried forcing repaint(). Nothing seems to want to update the widget properly.
I figured I'd post this in case anyone has run into this before. My work-around is going to be putting a QGraphicsEffect on all the child widgets and hope that "fixes" it. I tested this by putting it on one of the QLabels in the hbox and it faded perfectly as it was supposed to. But when put on the parent widget it doesn't work.
If it matters my QLabel "close button" image is not part of the layout but is a child of the widget. Maybe this is affecting it..
Thanks in advance.
Leonardo last edited by
Why don't you use the opacity property?
Thanks for the reply. I wasn't using QtQuick so I couldn't use that as you suggested but I tried using the C++ equivalent and it acted the same as the property animation. After all the QPropertyAnimation pretty much just works on the QGraphicsOpacityEffect directly which is probably exactly what QtQuick uses under the hood to do it's opacity.
Sorry for the delay in response I didn't realize the new forum system didn't email me when I got a response to a thread and I was busy enough with work not to check it. :)
Also, I figured out what was causing it. It seems that I was using a QLabel with setAutoFillBackground(true) and the opacity effect couldn't handle that for some reason. When I removed that (I'll find another way to draw the background) it fades out properly. Just in case anyone else gets here from google.