【问题标题】:Create a Transparent Blur Window创建透明模糊窗口
【发布时间】:2021-06-24 19:41:43
【问题描述】:

我正在使用 Python 3.9.1 和 PyQt6。现在我想创建一个背景模糊的窗口,应该如下所示:

模糊窗口背景演示

如果有人为此提供代码会很有帮助。

【问题讨论】:

  • 请花点时间阅读how to askgood questions 和how to check them,并考虑到StackOverflow 用户真的不会问“谁能告诉我我该怎么做xyz”。如果您的某些代码无法按预期工作,那么您可以提供minimal, reproducible example,我们很乐意提供帮助,否则此类问题一般不会得到解答。
  • 此外,在这种特定情况下,您不能直接使用 PyQt 执行此操作,您需要改用平台的 api(假设他们允许您这样做)。

标签: python pyqt pyside6 pyqt6


【解决方案1】:

真正的交易:

python -m pip install BlurWindow

import sys
from PySide2.QtWidgets import *
from PySide2.QtCore import *

from BlurWindow.blurWindow import blur



class MainWindow(QWidget):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.setAttribute(Qt.WA_TranslucentBackground)
        self.resize(500, 400)

        blur(self.winId())

        self.setStyleSheet("background-color: rgba(0, 0, 0, 0)")



if __name__ == '__main__':
    app = QApplication(sys.argv)
    mw = MainWindow()
    mw.show()
    sys.exit(app.exec_())

【讨论】:

    【解决方案2】:

    取自 KDE Plasma,现在用 Python 很容易做到这一点。

    详情请查看 - Watch this carefully

    您将需要使用提供的名为 fluentapp 的库 -

    For Project made with python - size 95 mb

    您需要从项目中提取它并使用提供的参考指南。 我已经尝试过它很酷,可以增强您的应用程序的美感。

    语法很简单,例如-

    import fluentapp.pyqt6.windowtools as wingui
    
    wingui.setWindowAlpha("0.5") # Make window transparent
    
    wingui.addGaussianBlur(radius=20, cover= False) 
    
    #if you want to use additional layer for dark and light theme, you can set cover True for dark.
     
         Your Code Here ---- 
    

    【讨论】:

      猜你喜欢
      • 2015-10-25
      • 2016-11-18
      • 2019-07-15
      • 1970-01-01
      • 2017-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多