PyQt5 创建透明窗口并设置透明度 案例
import sys
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtGui import QIcon, QBitmap, QPainter, QPixmap, QCursor, QMovie, QImage
from PyQt5.QtWidgets import QHBoxLayout, QPushButton, QMessageBox, QApplication, QVBoxLayout, QWidget, \
QLabel, QGridLayout, QLineEdit, QTextEdit, QFormLayout, QComboBox
'''
PyQt5 创建透明窗口并设置透明度 案例
'''
class OpacityWindowDemo(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
# 设置定位和左上角坐标
self.setGeometry(300, 300, 360, 260)
# 设置窗口标题
self.setWindowTitle('窗口透明度设置 的演示')
# 设置窗口图标
# self.setWindowIcon(QIcon('../web.ico'))
btn = QPushButton('第一个按钮',self)
vbox = QVBoxLayout()
vbox.addWidget(btn)
self.setLayout(vbox)
def mousePressEvent(self,event):
# 左击
if event.button() == Qt.LeftButton:
print(event.globalPos())
print(event.pos())
print(self.pos())
# 右击
if event.button() == Qt.RightButton:
self.close()
if __name__ == '__main__':
app = QApplication(sys.argv)
# 设置应用图标
app.setWindowIcon(QIcon('../web.ico'))
w = OpacityWindowDemo()
# 0-1,1表示不透明,0表示完全透明
w.setWindowOpacity(0.7)
w.show()
sys.exit(app.exec_())