How to display a Video/QVideoWidget inside a Qtreeview/QTreeWidgetItem
-
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
-
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 ?
-
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
-