我正在使用基于Qt 5.7.0的Qt Creator 4.0.2(GCC 4.9.1 20140922(Red Hat 4.9.1-10),64位)。
我正在小部件上显示图像,并在其顶部放置QButtons和QLabels。
看起来像这样:
我想使按钮半透明。没有任何属性。我尝试在另一个线程上给出答案:
ui->button->setStyleSheet("background-color: rgba(255, 255, 255, 50);");
但是它对我没有用。我也尝试过setStyleSheet("background:transparent;")
但这没有用。
请提出一种解决方法。
为按钮设置透明背景是不够的:您必须为主窗口小部件设置一些属性,以要求窗口管理器让按钮管理其自己的背景。
QWidget* w = new QWidget();
QPushButton* btn = new QPushButton("Click me", w);
btn->setStyleSheet("background-color: rgba(255, 255, 255, 50);");
w->setWindowFlags(Qt::FramelessWindowHint); // Do not display the window frame
w->setAttribute( Qt::WA_TranslucentBackground, true ); // Do not display the default background
w->show();