How to change the opacity of Qt MainWindow?

流过昼夜 提交于 2019-12-13 19:50:47

问题


How to change the opacity of the Qt MainWindow by some values?

My main window contains nothing but just somehow I need to change the opacity using keystrokes.

It looks like this now.

I tried to set using this->setWindowOpacity(0.5);

didn't get anything opacity effect.


回答1:


The below works for me most of times (as long as we can run in stylesheet override problem with other ways). Consider change the last component of rgba to less than 255 for making it semi-transparent.

widget->setStyleSheet("background-color: rgba(255, 255, 255, 255);");

Mind that child widgets may inherit the transparent background of parent widget by default unless you specify "background-color: rgba(255, 255, 255, 0);" for them or limit the visibility of upper stylesheet somehow e.g. "QMainWindow(background-color: rgba(255, 255, 255, 255);}".




回答2:


You can change the windowOpacity property using setProperty.

this->setProperty("windowOpacity", 0.5);


来源:https://stackoverflow.com/questions/30880559/how-to-change-the-opacity-of-qt-mainwindow

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!