Qt 子窗体无法设置透明度的问题--来自StackOverflow

一个弹窗,为了让跟随父窗体移动并且置顶,给设置了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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值