c++ - 在 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。
我在我的小部件上显示图像并将QButtons和QLabels放在它上面。
它看起来像这样:
我想让按钮半透明。它没有任何财产。我尝试了在另一个线程上给出的答案:
ui->button->setStyleSheet("background-color: rgba(255, 255, 255, 50);");
但这对我不起作用。我也试过setStyleSheet("background:transparent;")
了,但是没有用。
请提出一种方法。
解决方案
将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);
推荐阅读
- android - 创建虚拟显示后调用 release() 不起作用
- r - 如何替换r中列中字符串的第二个字符
- flutter - 如何在 Flutter 中创建如下所示的 UI
- spring - 在测试类之外使用 Spring Boot/JUnit 5 连接到测试生命周期事件
- php - 用两个表编码json数据
- eslint - 如何使用上次修改日期从 ESLint 中排除文件?
- java - 使用 log4j2 处理异常
- javascript - 函数执行后需要渲染 React js
- java - AWS lambda 使用 RestEasy 执行 http 请求:找不到内容类型应用程序/json 类型的编写器
- node.js - 节点使用 AJV 验证请求参数