<legend id='54xGs'><style id='54xGs'><dir id='54xGs'><q id='54xGs'></q></dir></style></legend>

    <small id='54xGs'></small><noframes id='54xGs'>

      1. <i id='54xGs'><tr id='54xGs'><dt id='54xGs'><q id='54xGs'><span id='54xGs'><b id='54xGs'><form id='54xGs'><ins id='54xGs'></ins><ul id='54xGs'></ul><sub id='54xGs'></sub></form><legend id='54xGs'></legend><bdo id='54xGs'><pre id='54xGs'><center id='54xGs'></center></pre></bdo></b><th id='54xGs'></th></span></q></dt></tr></i><div id='54xGs'><tfoot id='54xGs'></tfoot><dl id='54xGs'><fieldset id='54xGs'></fieldset></dl></div>
      2. <tfoot id='54xGs'></tfoot>
          <bdo id='54xGs'></bdo><ul id='54xGs'></ul>

        QtMediaPlayer在无框架和半透明背景PyQt5上不起作用

        QtMediaplayer wont work on frameless and translucent background PyQt5(QtMediaPlayer在无框架和半透明背景PyQt5上不起作用)
        <i id='FXwvV'><tr id='FXwvV'><dt id='FXwvV'><q id='FXwvV'><span id='FXwvV'><b id='FXwvV'><form id='FXwvV'><ins id='FXwvV'></ins><ul id='FXwvV'></ul><sub id='FXwvV'></sub></form><legend id='FXwvV'></legend><bdo id='FXwvV'><pre id='FXwvV'><center id='FXwvV'></center></pre></bdo></b><th id='FXwvV'></th></span></q></dt></tr></i><div id='FXwvV'><tfoot id='FXwvV'></tfoot><dl id='FXwvV'><fieldset id='FXwvV'></fieldset></dl></div>

          <bdo id='FXwvV'></bdo><ul id='FXwvV'></ul>

          <small id='FXwvV'></small><noframes id='FXwvV'>

              <tbody id='FXwvV'></tbody>
              <tfoot id='FXwvV'></tfoot>

                <legend id='FXwvV'><style id='FXwvV'><dir id='FXwvV'><q id='FXwvV'></q></dir></style></legend>

                • 本文介绍了QtMediaPlayer在无框架和半透明背景PyQt5上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在用QMediaPlayer制作一个视频播放器,但它在无边框和半透明的背景窗口上不起作用。我想做一个圆角窗口,所以我需要无边框和半透明的窗口。 以下是我的代码:

                  from PyQt5.QtCore import Qt, QUrl
                  from PyQt5.QtMultimedia import QMediaContent, QMediaPlayer
                  from PyQt5.QtMultimediaWidgets import QVideoWidget
                  from PyQt5.QtWidgets import QApplication,QMainWindow,QFrame
                  import sys     
                  class Player(QMainWindow):
                      def __init__(self, parent=None):
                          super().__init__(parent)
                          self.setWindowTitle("PyQt Video Player Widget Example") 
                          self.resize(600,400)
                          self.frame=QFrame(self)
                          self.frame.setStyleSheet('background:grey;border-radius:20px;')
                          self.setCentralWidget(self.frame)
                          #self.setWindowFlag(Qt.FramelessWindowHint)
                          #self.setAttribute(Qt.WA_TranslucentBackground)
                          self.mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface)
                          videoWidget = QVideoWidget(self.frame)
                          videoWidget.setGeometry(10,10,580,380)
                          self.resize(600,400)
                          self.mediaPlayer.error.connect(self.handleError)
                          self.mediaPlayer.setVideoOutput(videoWidget)
                          self.mediaPlayer.setMedia(
                                           QMediaContent(QUrl.fromLocalFile("C:/Users/mishra/Desktop/HiddenfilesWindow/10000000_1874628825927192_6229658593205944320_n(1).mp4")))
                          self.mediaPlayer.play()
                      def handleError(self):
                          print("Error: " + self.mediaPlayer.errorString())
                            
                  if __name__ == "__main__":
                      import sys
                      app = QApplication(sys.argv)
                      window = Player()
                      
                      window.show()
                      sys.exit(app.exec_())
                  

                  设置半透明背景后,它只播放音频而不播放视频。有人知道如何修复它吗?

                  推荐答案

                  试用:

                  import sys
                  from PyQt5.QtCore import Qt, QUrl, QRectF
                  from PyQt5.QtGui import QPainterPath, QRegion
                  from PyQt5.QtMultimedia import QMediaContent, QMediaPlayer
                  from PyQt5.QtMultimediaWidgets import QVideoWidget
                  from PyQt5.QtWidgets import QApplication, QMainWindow, QFrame, QWidget, QHBoxLayout
                       
                  
                  class Player(QMainWindow):
                      def __init__(self, parent=None):
                          super().__init__(parent)
                          self.setWindowTitle("PyQt Video Player Widget Example") 
                          self.resize(600,400)
                          self.frame= QFrame(self)  
                          
                  #        self.frame.setStyleSheet('background:grey; border-radius: 20px;')
                          self.setStyleSheet("Player {background: #000;}")                   # +++
                          
                          self.setCentralWidget(self.frame)
                  #        self.setWindowFlag(Qt.FramelessWindowHint)
                  #        self.setAttribute(Qt.WA_TranslucentBackground)
                  
                          layout = QHBoxLayout(self.frame)                                   # +++
                          videoWidget = QVideoWidget()                                       # +++
                          layout.addWidget(videoWidget)                                      # +++
                  
                          
                          self.mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface)
                  #        videoWidget = QVideoWidget(self.frame)             
                  #        videoWidget.setGeometry(10,10,580,380)
                  #        self.resize(600,400)
                          self.mediaPlayer.error.connect(self.handleError)
                          self.mediaPlayer.setVideoOutput(videoWidget)
                          self.mediaPlayer.setMedia(
                              QMediaContent(QUrl.fromLocalFile("Samonastrojka.avi")))
                          self.mediaPlayer.play()
                  
                  # +++ vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv        
                      def resizeEvent(self, event):
                          path = QPainterPath()
                          path.addRoundedRect(QRectF(self.rect()), 20, 20)
                          reg = QRegion(path.toFillPolygon().toPolygon())
                          self.setMask(reg)
                  # +++ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                          
                      def handleError(self):
                          print("Error: " + self.mediaPlayer.errorString())
                     
                     
                  if __name__ == "__main__":
                      app = QApplication(sys.argv)
                      window = Player()
                      window.show()
                      sys.exit(app.exec_())
                  

                  这篇关于QtMediaPlayer在无框架和半透明背景PyQt5上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                  Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)

                    <small id='hzijH'></small><noframes id='hzijH'>

                          <legend id='hzijH'><style id='hzijH'><dir id='hzijH'><q id='hzijH'></q></dir></style></legend>

                            <tbody id='hzijH'></tbody>

                          <tfoot id='hzijH'></tfoot>
                            <bdo id='hzijH'></bdo><ul id='hzijH'></ul>
                          • <i id='hzijH'><tr id='hzijH'><dt id='hzijH'><q id='hzijH'><span id='hzijH'><b id='hzijH'><form id='hzijH'><ins id='hzijH'></ins><ul id='hzijH'></ul><sub id='hzijH'></sub></form><legend id='hzijH'></legend><bdo id='hzijH'><pre id='hzijH'><center id='hzijH'></center></pre></bdo></b><th id='hzijH'></th></span></q></dt></tr></i><div id='hzijH'><tfoot id='hzijH'></tfoot><dl id='hzijH'><fieldset id='hzijH'></fieldset></dl></div>