如何更改 ui->widget->windowOpacity?
现在我想更改 ui->widget->windowOpacity 和 ui->stackedWidget->windowOpacity() ,但失败了。
void Widget::on_pushButton_clicked()
{
QTimer *timerOpacity = new QTimer(this);
connect(timerOpacity,SIGNAL(timeout()),this,SLOT(changeOpacity()));
timerOpacity->start(100);
}
void Widget::changeOpacity()
{
if (opalevel > 8) return;
double opacity[9] = {0.9,0.8,0.7,0.6,0.5,0.4,0.3,0.2,0.1};
ui->stackedWidget->setWindowOpacity(opacity[opalevel]);
ui->widget->setWindowOpacity(opacity[opalevel]);
this->setWindowOpacity(opacity[opalevel]);
qDebug()<<"opalevel = "<< opalevel <<" ui->widget opacity:"<<ui->widget->windowOpacity();
qDebug()<<"opalevel = "<< opalevel <<" ui->stackedWidget opacity:"<<ui->stackedWidget->windowOpacity();
qDebug()<<"opalevel = "<< opalevel <<" ui opacity : "<< this->windowOpacity()<<endl;
opalevel++;
}
调试日志:
opalevel = 0 ui->widget opacity: 1
opalevel = 0 ui->stackedWidget opacity: 1
opalevel = 0 ui opacity: 0.898039
opalevel = 1 ui->widget opacity: 1
opalevel = 1 ui->stackedWidget opacity: 1
opalevel = 1 ui opacity: 0.8
opalevel = 2 ui->widget opacity: 1
opalevel = 2 ui->stackedWidget opacity: 1
opalevel = 2 ui opacity: 0.698039
opalevel = 3 ui->widget opacity: 1
opalevel = 3 ui->stackedWidget opacity: 1
opalevel = 3 ui opacity: 0.596078
opalevel = 4 ui->widget opacity: 1
opalevel = 4 ui->stackedWidget opacity: 1
opalevel = 4 ui opacity: 0.498039
opalevel = 5 ui->widget opacity: 1
opalevel = 5 ui->stackedWidget opacity: 1
opalevel = 5 ui opacity: 0.4
opalevel = 6 ui->widget opacity: 1
opalevel = 6 ui->stackedWidget opacity: 1
opalevel = 6 ui opacity: 0.298039
opalevel = 7 ui->widget opacity: 1
opalevel = 7 ui->stackedWidget opacity: 1
opalevel = 7 ui opacity: 0.2
opalevel = 8 ui->widget opacity: 1
opalevel = 8 ui->stackedWidget opacity: 1
opalevel = 8 ui opacity: 0.0980392
谢谢您的帮助。
Now I want to change the ui->widget->windowOpacity and ui->stackedWidget->windowOpacity() ,but failed.
void Widget::on_pushButton_clicked()
{
QTimer *timerOpacity = new QTimer(this);
connect(timerOpacity,SIGNAL(timeout()),this,SLOT(changeOpacity()));
timerOpacity->start(100);
}
void Widget::changeOpacity()
{
if (opalevel > 8) return;
double opacity[9] = {0.9,0.8,0.7,0.6,0.5,0.4,0.3,0.2,0.1};
ui->stackedWidget->setWindowOpacity(opacity[opalevel]);
ui->widget->setWindowOpacity(opacity[opalevel]);
this->setWindowOpacity(opacity[opalevel]);
qDebug()<<"opalevel = "<< opalevel <<" ui->widget opacity:"<<ui->widget->windowOpacity();
qDebug()<<"opalevel = "<< opalevel <<" ui->stackedWidget opacity:"<<ui->stackedWidget->windowOpacity();
qDebug()<<"opalevel = "<< opalevel <<" ui opacity : "<< this->windowOpacity()<<endl;
opalevel++;
}
Debug log :
opalevel = 0 ui->widget opacity: 1
opalevel = 0 ui->stackedWidget opacity: 1
opalevel = 0 ui opacity: 0.898039
opalevel = 1 ui->widget opacity: 1
opalevel = 1 ui->stackedWidget opacity: 1
opalevel = 1 ui opacity: 0.8
opalevel = 2 ui->widget opacity: 1
opalevel = 2 ui->stackedWidget opacity: 1
opalevel = 2 ui opacity: 0.698039
opalevel = 3 ui->widget opacity: 1
opalevel = 3 ui->stackedWidget opacity: 1
opalevel = 3 ui opacity: 0.596078
opalevel = 4 ui->widget opacity: 1
opalevel = 4 ui->stackedWidget opacity: 1
opalevel = 4 ui opacity: 0.498039
opalevel = 5 ui->widget opacity: 1
opalevel = 5 ui->stackedWidget opacity: 1
opalevel = 5 ui opacity: 0.4
opalevel = 6 ui->widget opacity: 1
opalevel = 6 ui->stackedWidget opacity: 1
opalevel = 6 ui opacity: 0.298039
opalevel = 7 ui->widget opacity: 1
opalevel = 7 ui->stackedWidget opacity: 1
opalevel = 7 ui opacity: 0.2
opalevel = 8 ui->widget opacity: 1
opalevel = 8 ui->stackedWidget opacity: 1
opalevel = 8 ui opacity: 0.0980392
Thank you for your help .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在非顶级小部件上使用
QGraphicsOpacityEffect
:You can use
QGraphicsOpacityEffect
on your non-top-level widgets: