簡體   English   中英

PyQt5 小部件旨在透明以顯示 QVideoPlayer 通過視頻並采用 QMainWindow 背景

[英]PyQt5 widgets intended to be transparent to show QVideoPlayer pass through video and adopt QMainWindow background

我有一個 QMainWindow ,其中 QVideoWidget 設置為中央小部件。 該視頻就像我正在制作的二十一點游戲的主要 window 的背景。 我有兩個按鈕,我想以部分透明的方式放置在視頻頂部。

這就是我希望 window 的樣子:

在此處輸入圖像描述

但我已經嘗試了幾十種方法來實現透明按鈕背景並且不能。 任何透明度嘗試都會直接“剪切”視頻並顯示 MainWindow 的背景。 例如,我將主 window 背景設置為藍色。

這是運行時顯示的內容:

在此處輸入圖像描述

如何使視頻出現在透明按鈕后面?

我嘗試過但沒有成功的事情:堆疊布局設置為 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')

您可以嘗試: self.PlayCardsButton.setFlat(True)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM