首页 > 解决方案 > 在 Linux 的 QT C++ 中设置 QButtons 的透明度

问题描述

我正在使用基于 Qt 5.7.0(GCC 4.9.1 20140922(Red Hat 4.9.1-10),64 位)的 Qt Creator 4.0.2。

我在我的小部件上显示图像并将QButtonsQLabels放在它上面。

它看起来像这样:

带有图像和按钮的窗口

我想让按钮半透明。它没有任何财产。我尝试了在另一个线程上给出的答案:

ui->button->setStyleSheet("background-color: rgba(255, 255, 255, 50);");

但这对我不起作用。我也试过setStyleSheet("background:transparent;") 了,但是没有用。

请提出一种方法。

标签: c++qtqtstylesheetsqpushbutton

解决方案


将bg颜色设置为“透明”是不够的,还需要设置“border-style: outset;” 主窗口/小部件中没有其他内容......

ui->pushButton_7->setStyleSheet("background-color: transparent; style: outset;");

在此处输入图像描述

然后:

做:

ui->pushButton_7->setStyleSheet("background-color: #FF0011");
auto qgoEffect = new QGraphicsOpacityEffect(this);
qgoEffect->setOpacity(0.15);
ui->pushButton_7->setGraphicsEffect(qgoEffect);
ui->pushButton_7->setAutoFillBackground(true);

在此处输入图像描述


推荐阅读