PyQt - 如何淡化对话框后面的桌面背景(类似于 Windows UAC)? [英] PyQt - How do I fade the desktop background behind a dialog (similar to Windows UAC)?

查看:31
本文介绍了PyQt - 如何淡化对话框后面的桌面背景(类似于 Windows UAC)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 PYTHON 中的 pyqt 是否有这么多功能,但是是否可以将对话框放在屏幕中央(我知道有很多可能)和周围区域对话框外的不透明度约为 50%,因此基本上它仍然可见,但您无法完全看到它.这可能吗?确保你理解我在对话框之外而不是在里面谈论.我想要这个用于我的简单锁屏应用程序它不是很安全,但我稍后会处理.我试过了

I'm wondering if pyqt in PYTHON has this much capability, but is it possible to have the dialog be in the center of the screen(i know that much is possible) and the sourounding area out side of the dialog has an opacity of about of about 50 percent so basicly its still visable but you can't totatlly see it. is this possible? Make sure you understand im talking about outside of the dialog box not inside. I want this for my simple lockscreen app it not very secure but I'll work on that later. I have tried

self.setWindowOpacity(.8)

但这仅适用于我想影响到外面的窗口

but that only applies to the window i want to affet to the outside

我知道这听起来不太容易理解,但如果您需要更多解释,请在评论中告诉我.

I know this doesn't sound very easy to understand but if you need more explanation let me know in the comments.

推荐答案

您希望背景(桌面)的不透明度更低吗?背景后面"没有任何东西,因此更改不透明度没有任何意义.我猜您想要类似于 Windows UAC 对话框的工作方式.就像安装软件时会出现确认对话框一样,屏幕的其余部分会变黑.

Do you want the background (desktop) to have less opacity? There's nothing "behind" the background, so changing opacity doesn't make any sense. I guess you want something similar to how Windows UAC dialog works. Like when you install software a confirm dialog shows up and the rest of the screen goes blackish.

这可以通过创建一个单一颜色的全屏无边框窗口来模拟,降低不透明度,然后在其上打开对话框.

This can be emulated by creating a fullscreen borderless window in a single color with reduced opacity and open your dialog on top of that.

对于无框/无边框窗口,我找到了对 QtCore.Qt.FramelessWindowHint 和名为 QWindow.setMask() 的方法的引用.任何一个都可以.

For a frameless/borderless window i find references to QtCore.Qt.FramelessWindowHint and a method called QWindow.setMask(). Either one might work.

这是 FramelessWindowHint 用法的示例.

希望对您有所帮助.

添加了代码示例(基于链接中的示例):

Added code example (Based on the example from the link):

import sys
from PySide import QtCore, QtGui

class MyWindow(QtGui.QMainWindow):
    def __init__(self, parent=None):
        super(MyWindow, self).__init__(parent)
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.b = QtGui.QPushButton("exit", self, clicked=self.close)
        self.setWindowOpacity(.8)
        self.setStyleSheet("QMainWindow { background: 'black'}");

        self.dialog = QtGui.QDialog()
        self.dialog.setModal(True)
        self.dialog.show()

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    myapp = MyWindow()
    myapp.setGeometry(app.desktop().screenGeometry())
    myapp.show()
    sys.exit(app.exec_())

这仅适用于单个屏幕.您必须枚举屏幕并为每个单独的屏幕创建一个窗口以涵盖多屏幕设置.我将把它留给你作为练习.

This will only work for a single screen. You'll have to enumerate screens and create a window for each seperate screen to cover multi-screen setups. I'll leave that as an exercise for you.

这篇关于PyQt - 如何淡化对话框后面的桌面背景(类似于 Windows UAC)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆