setMinimumSize(QSize(800, 800));
setAttribute(Qt::WA_TranslucentBackground, true); //【1】
setStyleSheet ("background-color:transparent"); //【2】
setWindowFlags(Qt::FramelessWindowHint);
QPushButton* pButton = new QPushButton;
pButton->setParent(this);
pButton->setGeometry(100, 100, 200, 100);
pButton->setText("button");
pButton->setStyleSheet ("background-color: rgb(0,0,255, 100);color: rgb(255,255,255);");
通过以上设置可以得到全透明的背景窗口,实验发现【1】和【2】缺一不可,从函数字面上看感觉应该调用其中一个函数就可以实现全透明。后来想通过setStyleSheet ("background-color: rgb(100,100,0, 100)");设置半透明,发现没有效果,不知道有什么办法能够单独设置背景窗口半透明。如果调用setWindowOpacity()会使背景窗口和控件都透明。