【问题标题】:Totally Transparent for a QFrameQFrame 完全透明
【发布时间】:2020-04-30 21:40:42
【问题描述】:

我正在使用 Qt Creator 4.5.2(Qt 5.9.5,GCC 7.3.0 64 位)并在 Ubuntu 18.04 上运行。

我有一个 QT MainWindow(一个 QWidget),它是 QRectF(0,0,480,800)。在 MainWindow 上,有一个 QFrame,它是 QRectF(0,60,480,400)。我想让 QFrame 完全透明。换句话说,我想在 QFrame 框架后面看到 PC 桌面上的显示,但看不到 QT MainWindow 其他部分后面的桌面。

有可能吗? 我google了很多,没有找到好的解决方案。

我试过了:

setStyleSheet("QFrame{border: None; background-color: transparent;}");

setStyleSheet("background-color: transparent; QFrame{border: None; background-color: transparent;}");

setStyleSheet("QFrame{border: None; background-color: rgba(0,0,0,100;}");

它们都不起作用。

【问题讨论】:

    标签: c++ qt


    【解决方案1】:

    这对我有用

    widget->setStyleSheet("background-color: transparent;");
    widget->setWindowFlags(Qt::FramelessWindowHint);   //No windowing
    widget->setAttribute(Qt::WA_TranslucentBackground); // No background
    

    【讨论】:

    【解决方案2】:

    当您将 QFrame 添加到 QMainWindow 并将透明背景设置为 QFrame 时,QMainWindow 仍会填充一些颜色。您需要为 QFrame 设置透明样式:

    frame->setStyleSheet("border: none; background: transparent;");
    

    然后将属性设置为 QMainWindow:

    mainWindow->setAttribute(Qt::WA_TranslucentBackground);
    

    【讨论】:

    • 确实没用。我仍然看不到桌面部分。相反,我看到了我的应用程序的前一个屏幕。我的应用程序有多个屏幕。
    猜你喜欢
    • 2014-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多