我有一个QMainWindow,其中QVideoWidget设置为中央窗口小部件。该视频就像我正在制作的二十一点游戏的主窗口的背景一样。我有两个按钮想部分透明地放在视频上方。
这就是我想要的窗口外观:
但是我似乎已经尝试了数十种方法来实现透明按钮背景,但实际上并没有。任何尝试透明的操作都会“剪切”整个视频,并显示MainWindow的背景。例如,我将主窗口背景设置为蓝色。
这是运行时显示的内容:
如何使视频显示在透明按钮后面?
我尝试过的事没有成功:将堆叠布局设置为StackAll,使用透明颜色代码(rgba(0,0,0,0))在按钮样式表中插入透明背景图像,将videowidget设置为父窗口小部件按钮。
我的代码的相关部分:
from PyQt5 import QtWidgets, QtMultimediaWidgets, QtMultimedia, QtCore, QtGui, Qt
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QPushButton, QLineEdit, QComboBox
from PyQt5.QtGui import QTransform
import sys
import random
class MyWindow(QMainWindow):
def __init__(self):
super(MyWindow, self).__init__()
self.setGeometry(0, 0, 1920, 1080)
self.setWindowTitle("Cutie Pie Casino")
self.setStyleSheet('background-color: blue;')
self.Welcome()
def Welcome(self):
welcome_font = QtGui.QFont()
welcome_font.setPointSize(30)
welcome_font.setFamily('Broadway')
welcome_font_small = QtGui.QFont()
welcome_font_small.setPointSize(20)
welcome_font_small.setFamily('Broadway')
# create link to movie file
movie_file = QtCore.QUrl.fromLocalFile('C:/Users/Owner/PycharmProjects/Black Jack/video/'
'Cutie Pie Casino Video.mp4')
vid_media = QtMultimedia.QMediaContent(movie_file)
# create video widget
self.videoWidget = QtMultimediaWidgets.QVideoWidget()
self.videoWidget.setGeometry(0,0,1920,1080)
self.videoWidget.setStyleSheet('background-color: blue')
# create media player object (video widget goes in media player)
self.mediaPlayer = QtMultimedia.QMediaPlayer(None,
QtMultimedia.QMediaPlayer.VideoSurface)
self.mediaPlayer.setVideoOutput(self.videoWidget)
# playlist
self.playlist = QtMultimedia.QMediaPlaylist()
self.playlist.setCurrentIndex(0)
self.playlist.setPlaybackMode(QtMultimedia.QMediaPlaylist.Loop)
self.playlist.addMedia(vid_media)
# add content to media player
self.mediaPlayer.setPlaylist(self.playlist)
self.mediaPlayer.play()
self.setCentralWidget(self.videoWidget)
self.PlayCardsButton = QPushButton(self)
self.PlayCardsButton.setText('Play Blackjack')
self.PlayCardsButton.setFont(welcome_font_small)
self.PlayCardsButton.setGeometry(765,500,400,150)
self.PlayCardsButton.clicked.connect(self.InitializeTable)
self.PlayCardsButton.setStyleSheet('background-color: rgba(0,0,0,0); color: black')
self.GameSetupButton = QPushButton(self)
self.GameSetupButton.setGeometry(765, 700, 400, 150)
self.GameSetupButton.setFont(welcome_font_small)
self.GameSetupButton.setText('Game Setup')
self.GameSetupButton.setStyleSheet('background-color: rgba(0,0,0,0); color: black')
答案 0 :(得分:0)
您可以尝试:
self.PlayCardsButton.setFlat(True)