Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to display a Video/QVideoWidget inside a Qtreeview/QTreeWidgetItem
Forum Updated to NodeBB v4.3 + New Features

How to display a Video/QVideoWidget inside a Qtreeview/QTreeWidgetItem

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 453 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
    Aurele
    wrote on last edited by
    #1

    Hello,

    I am trying to display a short video as a thumbnail in a Qtreeview, where each treewidgetItem has a video that is played on mouse enter event,

    here is my python code

    
    from PySide2 import QtWidgets, QtCore, QtGui, QtMultimedia, QtMultimediaWidgets
    import sys
    from PySide2.QtCore import Qt
    
    class EntityView2(QtWidgets.QTreeWidget):
        """
            EntityView Entity View implemented by QtTreeWidget
        """
    
        def __init__(self, parent=None):
            #self.entities_items = []
            super(EntityView2, self).__init__(parent)
            self.items = []
            self.setWordWrap(True)
            super(EntityView2, self).setHeaderItem( QtWidgets.QTreeWidgetItem(["Entity Name", "Last Version", "Thumbnail", "Notes"]) )
            self.setColumnCount(4)
            self.header().setStretchLastSection(True)
            self.header().resizeSection(0, 150)
            self.header().resizeSection(1, 300)
            self.header().resizeSection(2, 150)
            self.panel_size = QtCore.QSize(120,100)
            self.pattern = None
    
            tree = QtWidgets.QTreeWidgetItem([None, None , None , None])
            tree.setSizeHint(0,self.panel_size)
            tree.setSizeHint(1,self.panel_size)
            tree.setSizeHint(2,self.panel_size)
            tree.setSizeHint(3,self.panel_size)
            tree.setData(0,4, "nom_entiter")
    
            super(EntityView2, self).addTopLevelItem(tree)
    
            open_note_label = QtWidgets.QLabel("open_notes")
            open_note_label.setWordWrap(True)
            name_label = QtWidgets.QLabel("entity.name")
            name_label.setWordWrap(True)
            version_label = QtWidgets.QLabel("version")
            version_label.setWordWrap(True)
            self.setItemWidget(tree, 3 , open_note_label)
            self.setItemWidget(tree, 0 , name_label)
            self.setItemWidget(tree, 1 , version_label)
    
            video_path = r"K:\02_SAISON_2\03_FABRICATION\ASSETS\Prop\Knife\shading\snap\v006\BDG__Prop__Knife__shading__thumbnail__v006.mov"
    
            widget = QtWidgets.QWidget()
            player = QtMultimedia.QMediaPlayer()
            playlist = QtMultimedia.QMediaPlaylist(player)
            playlist.addMedia(QtCore.QUrl(video_path))
            videoWidget = QtMultimediaWidgets.QVideoWidget(widget)
            player.setVideoOutput(videoWidget)
            tree.setData(2, Qt.DisplayRole, widget)
            player.play()
    
    app = QtWidgets.QApplication(sys.argv)
    Form = EntityView2()
    Form.show()
    app.exec_()
    

    Feel free to give advice in C++

    So i am stuck at the very beginning of the process because on the many methods i tried i can never get the video to display itself where i could get and QImage to get displayed

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      The default delegate does not know how to render widgets even less a QVideoWidget.

      Do you need to show the video in the cell itself or would a dedicated player beside the tree view be a possible alternative ?

      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
      • A Offline
        A Offline
        Aurele
        wrote on last edited by
        #3

        Hello,

        Thanks for the reply.

        I thought i would be complicated to do so inside the the treeItem.

        I see only 3 solutions then:

        • reimplement a custom delegate, but that would be a bit much for what i want, and i dont even know if its possible
        • having a succession of QImage to mimic a video but i think the frame rate would make this hard to do
        • and having a separated widget to display the video

        I think i'll go for for the separated widget

        1 Reply Last reply
        0
        • N Niccolo v referenced this topic on

        • Login

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