9

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.

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!

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).

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?

Thanks in advance.

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()
ekhumoro
  • 115,249
  • 20
  • 229
  • 336
troubled_sloth
  • 95
  • 1
  • 1
  • 5
  • 1
    There should be no problem in getting a transparent window as a partial overlay that's on top of the screen stack. All you need to do in Qt is to set a transparent window background color (through a stylesheet, for example), and raise your window so that it's on top of everything else. I don't know where you looked, but QWidget documentation has *everything* you need. In fact, a subtitle "player" would be around a 100 lines in Qt :) – Kuba hasn't forgotten Monica Sep 20 '14 at 15:00
  • Well so far I tried: QtCore.Qt.WindowStaysOnTopHint which is setting the window above all other windows, however it disappears behind a fullscreened video. Do I have to put it on top after the video is set to fullscreen mode? – troubled_sloth Sep 20 '14 at 15:06
  • As the previous commenter suggested, this should be a fairly trivial thing to accomplish. Please post a [MCV example](https://stackoverflow.com/help/mcve) that demonstrates the problems you are having rather than forcing people to guess what is wrong with your code. – ekhumoro Sep 20 '14 at 18:10
  • sorry, I don't have yet started working on code, I was trying this piece of code I edited into my initial post. – troubled_sloth Sep 20 '14 at 18:20

2 Answers2

14

Update for PyQt5 pip install PyQt5

import sys

from PyQt5 import QtGui, QtCore, uic
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QMainWindow, QApplication


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

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


if __name__ == '__main__':
    app = QApplication(sys.argv)
    mywindow = MainWindow()
    mywindow.show()
    app.exec_()
Most Wanted
  • 6,254
  • 5
  • 53
  • 70
8

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_()
ekhumoro
  • 115,249
  • 20
  • 229
  • 336