问题
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