首页 > 其他分享 >VideoWidget with QGraphicsView

VideoWidget with QGraphicsView

时间:2022-11-02 09:58:47浏览次数:86  
标签:QGraphicsView Qt self graphicsView scene QtWidgets VideoWidget image

from PySide6 import QtWidgets, QtGui
from PySide6.QtCore import QRectF, Qt
from PySide6.QtMultimediaWidgets import QGraphicsVideoItem


class VideoWidget(QtWidgets.QWidget):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.videoItem = QGraphicsVideoItem()
        self.videoItem.setAspectRatioMode(Qt.KeepAspectRatio)
        self.scene = QtWidgets.QGraphicsScene(self)
        self.graphicsView = QtWidgets.QGraphicsView(self.scene)
        self.graphicsView.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.graphicsView.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.scene.addItem(self.videoItem)

        layout = QtWidgets.QVBoxLayout()
        layout.addWidget(self.graphicsView)
        self.setLayout(layout)
        self.image_ = None
        if self.height() != 0:
            self.des_w_h_ratio_ = self.width() / self.height()
        self.src_w_h_ratio_ = float()
        self.scale_w_ = int()
        self.scale_h_ = int()
        pass

    def set_image(self, image):
        # self.image_ = image
        # self.src_w_h_ratio_ = self.image_.width() / self.image_.height()
        # self.update()
        # w = image.width()
        # h = image.height()

        self.scene.clear()
        # image = QtGui.QPixmap.fromImage(image)
        self.scene.addPixmap(image)
        self.graphicsView.fitInView(QRectF(0, 0, self.width(), self.height()), Qt.KeepAspectRatio)
        pass

标签:QGraphicsView,Qt,self,graphicsView,scene,QtWidgets,VideoWidget,image
From: https://www.cnblogs.com/kk0716/p/16850001.html

相关文章

  • VideoWidget with pyqtgraph ImageView
    importtimefromPySide6importQtWidgets,QtGui,QtCore,QtOpenGLWidgetsfromPySide6.QtGuiimportQOpenGLFunctions,QVector2D,QVector3D,QMatrix4x4fromPy......
  • VideoWidget
    fromPySide6importQtWidgets,QtGui,QtCore#classVideoWidget(QtOpenGLWidgets.QOpenGLWidget):classVideoWidget(QtWidgets.QWidget):def__init__(self,......