#include "elevideo.h" #include EleVideo::EleVideo(QString path, QWidget *parent) : QVideoWidget{parent} { setAspectRatioMode(Qt::IgnoreAspectRatio); QMediaPlayer* player = new QMediaPlayer(this); player->setMedia(QUrl::fromLocalFile(path)); player->setVideoOutput(this); if(isVisible()) player->play(); } void EleVideo::showEvent(QShowEvent *) { ((QMediaPlayer*)mediaObject())->play(); } void EleVideo::hideEvent(QHideEvent *) { ((QMediaPlayer*)mediaObject())->stop(); }