Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Auto play video files in tablewidget



  • Hi.
    Is it possible to display videos in a tablewidget just like you would display an image?

    I thought I'd ask here first before I even try.

    Best regards,
    Megamouse


  • Lifetime Qt Champion

    Hi,

    If you mean as using the decoration role, then no, you'll have to implement that yourself.



  • Example: add five row with videowidget

    ui->tableWidget->setColumnCount(2);
    for(int i=0;i<5;i++)
    {
    QLabel *label = new QLabel(this);
    label->setText("VIDEO"+QString::number(i+1));
    QVideoWidget *videoWidget = new QVideoWidget(this);
    QMediaPlayer *mediaPlayer = new QMediaPlayer;
    mediaPlayer->setVideoOutput(videoWidget);
    QMediaPlaylist *Mplaylist = new QMediaPlaylist;
    Mplaylist->setPlaybackMode(QMediaPlaylist::Loop);
    Mplaylist->addMedia(QUrl::fromLocalFile("/root/Videos/Akon.mp4")); // add playlist
    mediaPlayer->setPlaylist(Mplaylist);
    ui->tableWidget->insertRow(ui->tableWidget->rowCount());
    ui->tableWidget->setCellWidget(ui->tableWidget->rowCount()-1,0,label);
    ui->tableWidget->setCellWidget(ui->tableWidget->rowCount()-1,1,videoWidget);
    mediaPlayer->play();
    }

    you can handle it's own way .


Log in to reply