Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. I have sample show video app, can you guys check for me pls ?
Forum Updated to NodeBB v4.3 + New Features

I have sample show video app, can you guys check for me pls ?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 164 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ALBERT NGUYEN
    wrote on last edited by
    #1

    QML:
    VideoItem {
    id: videoItem
    anchors.fill: parent

                Connections {
                    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, Slot

    class 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"))
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved