I have sample show video app, can you guys check for me pls ?
Unsolved
QML and Qt Quick
-
QML:
VideoItem {
id: videoItem
anchors.fill: parentConnections { target: videoController function onFrameReady(frame) { if (window.isPlaying && videoItem) { try { videoItem.updateFrame(frame) window.frameCount++ debugText.text = "Frames: " + window.frameCount } catch (e) { console.error("Error updating frame:", e) } } } function onErrorOccurred(error) { window.errorMessage = error if (error) { loadingIndicator.visible = true } else { loadingIndicator.visible = false } } function onConnectionStatusChanged(status) { loadingIndicator.visible = !status } } }
video_item.py:
from PySide6.QtQuick import QQuickPaintedItem
from PySide6.QtGui import QImage, QPainter
from PySide6.QtCore import Qt, Slotclass VideoItem(QQuickPaintedItem):
def init(self, parent=None):
super().init(parent)
self._frame = None
self.setRenderTarget(QQuickPaintedItem.FramebufferObject)
self.setAntialiasing(True)def paint(self, painter: QPainter): if self._frame is None: return # Scale image to fit while maintaining aspect ratio rect = self.boundingRect() scaled_image = self._frame.scaled( rect.width(), rect.height(), Qt.KeepAspectRatio, Qt.SmoothTransformation ) # Center the image x = (rect.width() - scaled_image.width()) / 2 y = (rect.height() - scaled_image.height()) / 2 painter.drawImage(x, y, scaled_image) @Slot(QImage) def updateFrame(self, frame): if frame is None: return self._frame = frame self.update() @Slot() def releaseResources(self): self._frame = None self.update()
Main py:
qmlRegisterType(VideoItem, "CustomVideo", 1, 0, "VideoItem")# Khởi tạo controller controller = VideoController() # Thiết lập QML engine.rootContext().setContextProperty("videoController", controller) engine.load(QUrl.fromLocalFile("customvideo.qml"))
-
Hi and welcome to devnet,
What exactly are you expecting from people here ?
On a side note, please using coding tags (using for example de
</>
button) to make your code readable.