一个弹窗,为了让跟随父窗体移动并且置顶,给设置了parent,但是一旦设置了parent,关闭的消失效果动画就出不来了。即问题是:当一个QWidget设置了parent,用QPropertyAnimation,设置"windowOpacity"就失败。
解决办法看了很多博客都乱写一通没人能看懂,解决问题还得Stack Overflow。。。我搬运过来Mark一下:
提问:
I've used QPropertyAnimation
to change the opacity of a QWidget within a specific duration, let's say a QLabel. However I found that once I give a QWidget a parent, setWindowOpacity
doesn't work for it.
MainWindow w;
// code worked as expected
QLabel label;
label.setFixedSize(100, 100);
label.setStyleSheet("background-color: red");
label.setWindowOpacity(0);
QPropertyAnimation animation(&label, "windowOpacity");
animation.setDuration(2000);
animation.setStartValue(0.1);
animation.setEndValue(1.0);
label.show();
animation.start();
// windowOp