I have a QMainWindow with a QVideoWidget set as the central widget. The video is acting like a background to the main window of the blackjack game I'm making. I have two buttons I'd like to place on top of the video with partial transparency.
This is what I want the window to look like:
but I've tried seemingly dozens of ways to achieve the transparent button background and can't. Any attempt at transparency 'cuts' straight through the video and shows the background of the MainWindow instead. For example, I have the main window background set to blue.
This is what shows when run:
How can I make the video appear behind the transparent buttons instead?
Things I've tried without success: stacked layouts set to StackAll, inserting transparent background images in the button stylesheets, using transparent color codes (rgba(0,0,0,0)), setting the videowidget as the parent widget to the buttons.
The relevant portion of my code:
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')