Qt上的C ++:控制标签和按钮的透明度

问题描述 投票:7回答:4

[好吧,我再次尝试使用Qt Creator上的Linux GUI应用程序,我在项目的Qt资源文件中添加了两个图像。而且我尝试在主窗口以及其他窗口和对话框中添加漂亮的背景。我使用的是样式表选项(无编码)。

我无法设置标签和按钮的透明度。 Qt创建者GUI本身提供有关如何执行此操作的任何想法?!I am attaching a snap of how my application looks.

c++ qt user-interface stylesheet qt-designer
4个回答
8
投票

您可以通过设置样式表来设置QLabel或QPushbutton的透明度:

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

您还可以在设计器中的小部件的styleSheet属性中添加background-color: rgba(255, 255, 255, 0);

第四个参数是alpha。通过将alpha设置为大于零的某个值,您还可以使用半透明的小部件:

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

5
投票

ui元素属性的QWidget部分(在qtDesigner视图的右下方)具有“窗口不透明度”属性。默认情况下,它是1.0(完全不透明)。

It is also available programmatically


1
投票

这对我有用:

this->setWindowOpacity(0.35);
this->setAttribute(Qt::WA_TranslucentBackground, false);
this->setStyleSheet("background-color: yellow;");

0
投票

不是来自GUI,但对某人仍然有用:

    auto effect = new QGraphicsOpacityEffect(this);
    effect->setOpacity(0.5);
    yourWidget->setGraphicsEffect(effect);
    yourWidget->setAutoFillBackground(true);

here失窃。

© www.soinside.com 2019 - 2024. All rights reserved.