背景が透明のウインドウ。
成果物
コード
transparent.py
#!/usr/bin/python3 # -*- coding: utf-8 -*- import sys, os, numpy, PIL, csv from PySide2 import QtCore, QtGui, QtWidgets from PIL import Image, ImagePalette, ImageQt, ImageSequence class Window(QtWidgets.QMainWindow): def __init__(self): super(self.__class__, self).__init__() self.setAcceptDrops(True) self.setWindowTitle("Transparent window") self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True) palette = QtGui.QPalette(QtCore.Qt.transparent) self.setPalette(palette); self.setAutoFillBackground(True); self.show() def paintEvent(self, event): p = QtGui.QPainter(self) p.fillRect(self.rect(), QtCore.Qt.transparent); if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) window = Window() sys.exit(app.exec_())
端末を起動し、以下コマンドを叩く。
tab1
xcompmgr -c
端末で新しいタブを開き、以下コマンドを叩く。
tab2
./transparent.py
問題
不安定。成功率50%くらい? 初回起動時には大抵、背景が黒になってしまう。一度終了し、再度起動させる。これを背景が透明になるまで繰り返す。大抵は3回もやれば透明になる。
端末のタブを2つ使う。xcomp -c
で継続使用するタブと、窓実行用タブ。
tab1
xcompmgr -c
tab2
./transparent.py
所感
不安定なのが残念。
対象環境
- Raspbierry pi 4 Model B
- Raspbian buster 10.0 2019-09-26 ※
- bash 5.0.3(1)-release
- Qt 5.11
- Python 3.7.3
- PySide2
- Pillow 7.1.2
$ uname -a Linux raspberrypi 4.19.97-v7l+ #1294 SMP Thu Jan 30 13:21:14 GMT 2020 armv7l GNU/Linux