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. QVideo Widget should show the first frame after set it.

QVideo Widget should show the first frame after set it.

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 3.1k 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.
  • K Offline
    K Offline
    KonradMD
    wrote on last edited by KonradMD
    #1

    Hi,

    I am working with a QVideoWidget and if I start my programm a video is set in the background. But it does not show the first frame. So it looks like nothing is load. But if I move the window, I can see the already drawn first frame. But it looks like it is in the background. I really dont know whats in front. It is the same with an resizing event, I directly loose the preview frame.

    It is a mediaWidget in the mainwindow, and a QVideowidget with the mediaWidget as parent. So it seems not logic for me.

    I implemented everything normaly.

    ...
    mediaPlayerWidget = new QVideoWidget(_pMainWindow);
    mediaPlayerWidget->setParent(_pMainUi->mediawidget);

    _moviePlayer = new QMediaPlayer(this);
    _moviePlayer->setVideoOutput( mediaPlayerWidget);
    _moviePlayer->setMedia(QUrl::fromLocalFile(moviePath));
    ...
    void Video::play(state)
    {
    if(state()!=QMediaPlayer::PlayingState)
    {
    _moviePlayer->play();
    }
    }

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

      Hi,

      Why are you parenting mediaPlayerWidget like that ? That part looks a bit suspicious.

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

        Hi @SGaist

        If I want to use a QVideoWidget I could not put it directly into my Qt Creator. So I put a Widget first and then I created a VideoWidget and set the Widget from the QtCreator as parent.

        Is there a better way? Just creating the videoWidget and set it to the Layout manually? I tested your way:

        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        #include <QWidget>
        
        MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
        
            videoWidgetTransform     = new QVideoWidget(this);
            videoWidgetTransform->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
        
        
            videoWidgetLayout = new QVBoxLayout(this);
            videoWidgetLayout->addWidget(videoWidgetTransform);
            videoWidgetLayout->setMargin(0);
        
            _videoPlayer =  new QMediaPlayer(this);
            _videoPlayer->setVideoOutput(videoWidgetTransform);
            _videoPlayer->setMedia(QUrl::fromLocalFile("C:/Users/Public/Videos/Sample Videos/Wildlife.wmv"));
           connect(_videoPlayer,SIGNAL(stateChanged(QMediaPlayer::State)),_videoPlayer,SLOT(play()));
        }
        
        
        MainWindow::~MainWindow()
        {
            delete ui;
            delete _videoPlayer;
            delete videoWidgetTransform;
            delete videoWidgetLayout;
        }
        void MainWindow::resizeEvent(QResizeEvent *event)
        {
            Q_UNUSED(event)
            QSize s = this->size();
        
        
        
            if(this->height()*16/9>this->size().width() && this->width()*9/16<this->size().height())
            {
                s.setHeight(s.width()*9/16);
                s.setWidth(this->width());
        
            }
            else
            {
                s.setWidth(s.height()*16/9);
                s.setHeight(this->height());
            }
        
            videoWidgetTransform->setGeometry((this->width()-s.width())/2,(this->height()-s.height())/2,s.width(),s.height());
        }
        

        I still have the same problem, taht the first frame is not shown

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

          Why are you not calling the base implementation of resizeEvent ?

          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
          • K Offline
            K Offline
            KonradMD
            wrote on last edited by
            #5

            How do you mean @SGaist ?
            Is below the part of resize Event you mean?

            The widget will be erased and receive a paint event immediately after processing the resize event. No drawing need be (or should be) done inside this handler.
            

            I want to resize the videoWidget by 16:9, thats working properly.

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

              Have a call to QMainWindow::resizeEvent at the end of the method.

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

              K 1 Reply Last reply
              1
              • SGaistS SGaist

                Have a call to QMainWindow::resizeEvent at the end of the method.

                K Offline
                K Offline
                KonradMD
                wrote on last edited by
                #7

                @SGaist said in QVideo Widget should show the first frame after set it.:

                Have a call to QMainWindow::resizeEvent at the end of the method.

                I dont have another method than resizeEvent(). callinf resizeEvent in resizeEvent would be a loop.
                Where exactly would you implement it?

                J.HilkJ 1 Reply Last reply
                0
                • K KonradMD

                  @SGaist said in QVideo Widget should show the first frame after set it.:

                  Have a call to QMainWindow::resizeEvent at the end of the method.

                  I dont have another method than resizeEvent(). callinf resizeEvent in resizeEvent would be a loop.
                  Where exactly would you implement it?

                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #8

                  @KonradMD hi, what @SGaist meant is to add QMainWindow::resizeEvent(event); which is not the same as resizeEvent(event).

                  resizeEvent() calls your custom overwritten implementation, QMainWindow::resizeEvent calls the base implementation resizeEvent.


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  2
                  • K Offline
                    K Offline
                    KonradMD
                    wrote on last edited by
                    #9

                    Unfortunaly it does not work, I still see the frame when I am resizing, but not when I finished resizing.

                    Does it work on your systems? Maybe I just have a bad computer ... :/

                    void MainWindow::resizeEvent(QResizeEvent *event)
                    {
                        Q_UNUSED(event)
                        QSize s = this->size();
                    
                    
                    
                        if(this->height()*16/9>this->size().width() && this->width()*9/16<this->size().height())
                        {
                            s.setHeight(s.width()*9/16);
                            s.setWidth(this->width());
                    
                        }
                        else
                        {
                            s.setWidth(s.height()*16/9);
                            s.setHeight(this->height());
                        }
                    
                        videoWidgetTransform->setGeometry((this->width()-s.width())/2,(this->height()-s.height())/2,s.width(),s.height());
                        QMainWindow::resizeEvent(event);
                    }
                    
                    1 Reply Last reply
                    0

                    • Login

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