[PyQt] Problem with a widget [PyQt5]

Nikola Tesla rubymotions at gmail.com
Fri Feb 21 20:31:02 GMT 2020


/Hey, how are you? I hope you're well.
my problem is that I'm trying to add the class
video = QVideoWidget()
in this widget --> self.video_container = QWidget(self.box_video)
but I haven't been able to work it out... please help
I have attached the code file to make my question more understandable/

/
/

/This is so that the uploaded video can be displayed in that widget/

/This widget is illustrated in the attached image/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20200221/1828ccff/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foto_muestra.png
Type: image/png
Size: 41413 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20200221/1828ccff/attachment-0001.png>
-------------- next part --------------
# -*- coding: utf-8 -*-

from PyQt5.QtGui import QFont, QCursor, QIcon, QPixmap

from PyQt5.QtCore import Qt, QSize, QUrl

from PyQt5.QtWidgets import QWidget, QListWidget, QFrame, QGridLayout, QSlider, QLabel, QPushButton, QApplication, QMainWindow, QAbstractItemView, QGroupBox, QHBoxLayout, QFileDialog

from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent

from PyQt5.QtMultimediaWidgets import QVideoWidget 

import sys

import imagenes

class Catarsis(QMainWindow):

    def __init__(self):
        super().__init__()

        self.setWindowTitle("    Catarsis")
        self.setWindowIcon(QIcon('img/vector.jpg'))
        self.setObjectName("Catarsis")
        self.resize(814, 600)

        font = QFont()
        font.setFamily("Cascadia Code PL")
        font.setPointSize(16)
        self.setFont(font)

        self.artilugios()
        self.show()

    def artilugios(self):

        self.contenedor = QWidget(self)
        self.contenedor.setObjectName("contenedor")
        self.grid_1 = QGridLayout(self.contenedor)
        self.grid_1.setObjectName("grid_1")

        self.box_controles = QGroupBox(self.contenedor)
        self.box_controles.setMaximumSize(QSize(16777215, 122))
        self.box_controles.setObjectName("box_controles")
        self.gridLayout_2 = QGridLayout(self.box_controles)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.reproducir = QPushButton(self.box_controles)
        self.reproducir.setMaximumSize(QSize(50, 109))
        self.reproducir.setText("")

        icon = QIcon()
        icon.addPixmap(QPixmap(":/img/play.svg"), QIcon.Normal, QIcon.Off)

        self.reproducir.setIcon(icon)
        self.reproducir.setIconSize(QSize(48, 29))
        self.reproducir.setEnabled(False)
        self.reproducir.setFlat(True)
        self.reproducir.setObjectName("reproducir")
        self.reproducir.clicked.connect(self.play_video)

        self.gridLayout_2.addWidget(self.reproducir, 0, 0, 1, 1)
        self.parar = QPushButton(self.box_controles)
        self.parar.setMaximumSize(QSize(50, 109))
        self.parar.setText("")

        icon1 = QIcon()
        icon1.addPixmap(QPixmap(":/img/stop.svg"), QIcon.Normal, QIcon.Off)

        self.parar.setIcon(icon1)
        self.parar.setIconSize(QSize(48, 29))
        self.parar.setFlat(True)
        self.parar.setObjectName("parar")

        self.gridLayout_2.addWidget(self.parar, 0, 1, 1, 1)
        self.atras = QPushButton(self.box_controles)
        self.atras.setMaximumSize(QSize(50, 109))
        self.atras.setText("")

        icon2 = QIcon()
        icon2.addPixmap(QPixmap(":/img/back.svg"), QIcon.Normal, QIcon.Off)

        self.atras.setIcon(icon2)
        self.atras.setIconSize(QSize(48, 29))
        self.atras.setFlat(True)
        self.atras.setObjectName("atras")

        self.gridLayout_2.addWidget(self.atras, 0, 2, 1, 1)
        self.adelante = QPushButton(self.box_controles)
        self.adelante.setMaximumSize(QSize(50, 109))
        self.adelante.setText("")

        icon3 = QIcon()
        icon3.addPixmap(QPixmap(":/img/next.svg"), QIcon.Normal, QIcon.Off)

        self.adelante.setIcon(icon3)
        self.adelante.setIconSize(QSize(48, 29))
        self.adelante.setFlat(True)
        self.adelante.setObjectName("adelante")

        self.gridLayout_2.addWidget(self.adelante, 0, 3, 1, 1)
        self.cargar = QPushButton(self.box_controles)
        self.cargar.setMaximumSize(QSize(50, 109))
        self.cargar.clicked.connect(self.abrir_archivo)
        self.cargar.setText("")

        icon4 = QIcon()
        icon4.addPixmap(QPixmap(":/img/eject-1.svg"), QIcon.Normal, QIcon.Off)

        self.cargar.setIcon(icon4)
        self.cargar.setIconSize(QSize(48, 29))
        self.cargar.setFlat(True)
        self.cargar.setObjectName("cargar")

        self.gridLayout_2.addWidget(self.cargar, 0, 4, 1, 1)
        self.datos = QLabel(self.box_controles)
        self.datos.setFrameShape(QFrame.StyledPanel)
        self.datos.setIndent(13)
        self.datos.setObjectName("datos")

        self.gridLayout_2.addWidget(self.datos, 0, 5, 1, 1)
        self.menu = QPushButton(self.box_controles)
        self.menu.setMaximumSize(QSize(50, 109))
        self.menu.setText("")

        icon5 = QIcon()
        icon5.addPixmap(QPixmap(":/img/menu2.png"), QIcon.Normal, QIcon.Off)

        self.menu.setIcon(icon5)
        self.menu.setIconSize(QSize(48, 29))
        self.menu.setFlat(True)
        self.menu.setObjectName("menu")

        self.gridLayout_2.addWidget(self.menu, 0, 6, 1, 1)
        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")

        self.tiempo = QSlider(self.box_controles)
        self.tiempo.setOrientation(Qt.Horizontal)
        self.tiempo.setObjectName("tiempo")

        self.horizontalLayout.addWidget(self.tiempo)
        self.logo_volumen = QPushButton(self.box_controles)
        self.logo_volumen.setMaximumSize(QSize(41, 41))
        self.logo_volumen.setText("")

        icon6 = QIcon()
        icon6.addPixmap(QPixmap(":/img/altavoz3.png"), QIcon.Normal, QIcon.Off)

        self.logo_volumen.setIcon(icon6)
        self.logo_volumen.setIconSize(QSize(25, 25))
        self.logo_volumen.setFlat(True)
        self.logo_volumen.setObjectName("logo_volumen")

        self.horizontalLayout.addWidget(self.logo_volumen)
        self.volumen = QSlider(self.box_controles)
        self.volumen.setMaximumSize(QSize(139, 16777215))
        self.volumen.setPageStep(1)
        self.volumen.setOrientation(Qt.Horizontal)
        self.volumen.setObjectName("volumen")
        self.horizontalLayout.addWidget(self.volumen)

        self.gridLayout_2.addLayout(self.horizontalLayout, 1, 0, 1, 7)
        self.grid_1.addWidget(self.box_controles, 0, 0, 1, 1)

        self.box_video = QGroupBox(self.contenedor)
        self.box_video.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignVCenter)
        self.box_video.setFlat(False)
        self.box_video.setObjectName("box_video")

        self.gridLayout = QGridLayout(self.box_video)
        self.gridLayout.setObjectName("gridLayout")

        self.video_contenedor = QWidget(self.box_video)
        self.video_contenedor.setObjectName("video_contenedor")
        self.gridLayout.addWidget(self.video_contenedor, 0, 0, 1, 1)

        self.lista = QListWidget(self.box_video)
        self.lista.setMaximumSize(QSize(270, 16777215))
        self.lista.setObjectName("lista")
        self.gridLayout.addWidget(self.lista, 0, 1, 1, 1)
        self.grid_1.addWidget(self.box_video, 1, 0, 1, 1)

        self.media = QMediaPlayer(None, QMediaPlayer.VideoSurface)
        video = QVideoWidget()

        self.media.setVideoOutput(video)

        self.setCentralWidget(self.contenedor)

        self.box_controles.setTitle("Controles")
        self.datos.setText("TextLabel")
        self.box_video.setTitle("Catarsis Reproductor")

    def abrir_archivo(self):
        nombre_archivo, _ = QFileDialog.getOpenFileName(self, '   Abrir Video !!!', '', 'mp3 Audio (*.mp3);mp4 Video (*.mp4);Movie files (*.mov);All files (*.*)')

        if nombre_archivo != '':
            self.media.setMedia(QMediaContent(QUrl.fromLocalFile(nombre_archivo)))
            self.reproducir.setEnabled(True)

    def play_video(self):
        if self.media.state() == QMediaPlayer.PlayingState:
            self.media.pause()
        else:
            self.media.play()



if __name__ == "__main__":

    player = QApplication(sys.argv)
    # ['windowsvista', 'Windows', 'Fusion'] Posibles estilos en Windows 10
    player.setStyle('Fusion')
    ct = Catarsis()
    sys.exit(player.exec())


More information about the PyQt mailing list