使用 qt 创建透明叠加层 [英] Creating a transparent overlay with qt

查看:124
本文介绍了使用 qt 创建透明叠加层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在学习 python,现在我想(尝试)创建我的第一个真正的应用程序,一个适用于 Linux 的字幕播放器.到目前为止,我一直在使用 Greenfish 字幕播放器,它是针对 Windows 用户的,在 Linux 中不能正常工作.

I've been learning python recently and now I wanted to (try to) create my first real application, a subtitle player for Linux. So far I've been using the Greenfish subtitle player, which is aimed at Windows users and not properly working in Linux.

我想在 qt 中创建应用程序,因为我发现在 tkinter 中无法实现透明窗口,但是如果有人知道更好的框架,请提出建议!

I wanted to create the application in qt, since I discovered that transparent windows are not possible in tkinter, but if anybody knows a better framework please suggest!

现在在开始之前,我已经研究了几个小时的网络,以发现如何让我的应用程序显示在全屏 Flash 视频上,但似乎这是不可能的.然而,前面提到的 GF 字幕播放器在 Windows 中设法这样做,但在 Linux 中却没有(可能也是因为它通过 wine 运行).

Now before starting I've been researching the web for several hours to discover how to get my application to show over a full screened flash video and it seems like this is not possible. However the aforementioned GF subtitle player manages to do so in Windows, but not in Linux(maybe it's also because it's running through wine).

所以我的问题是有没有可能创建一个透明的应用程序,它可以保留在全屏 Flash 视频上,如果是这样,你能指出我正确的方向吗?

So my question is it possible to create a transparent application that remains over a fullscreened flash video and if so, could you point me in the right direction?

提前致谢.

这是我一直在尝试的一些示例代码.这段代码产生的窗口不会停留在全屏视频上方

edit: here some example code I've been trying. The window produced by this piece of code does not stay above a fullscreened video

import sys
from PyQt4 import QtGui, QtCore

class mymainwindow(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self, None, QtCore.Qt.WindowStaysOnTopHint)

app = QtGui.QApplication(sys.argv)
mywindow = mymainwindow()
mywindow.show()
app.exec_()
mywindow.show()

推荐答案

下面的示例代码将创建一个居中的无框窗口,该窗口应位于 Linux 上所有其他窗口的顶部(您可以单击该窗口将其关闭).

The example code below will create a centred, frameless window that should stay on top of all other windows on Linux (you can click on the window to close it).

import sys
from PyQt4 import QtGui, QtCore

class mymainwindow(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.setWindowFlags(
            QtCore.Qt.WindowStaysOnTopHint |
            QtCore.Qt.FramelessWindowHint |
            QtCore.Qt.X11BypassWindowManagerHint
            )
        self.setGeometry(QtGui.QStyle.alignedRect(
            QtCore.Qt.LeftToRight, QtCore.Qt.AlignCenter,
            QtCore.QSize(220, 32),
            QtGui.qApp.desktop().availableGeometry()))

    def mousePressEvent(self, event):
        QtGui.qApp.quit()

app = QtGui.QApplication(sys.argv)
mywindow = mymainwindow()
mywindow.show()
app.exec_()

这篇关于使用 qt 创建透明叠加层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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