display image in qvideowidget qmediaplayer possible?
-
Hi,
Aren't you trying to show an image rather than a video ?
-
@jsulm Oo, I've managed to miss that phrase…
I'd rather use a QStackedLayout with a QLabel to show the image and when you want to start the video, switch to the QVideoWidget.
-
This might be totaly wrong way to do it but I just found another approach. I created a QWidget with a stylesheet background image and when I press "video start" I call the camera part but with the QCameraViewfinder parented to the QWidget. I had to add setGeometry to get proper display of the video.
void AlignmentDialog::on_pushButton_video_start_clicked() { vf = new QCameraViewfinder(ui->widget_video); cam->setViewfinder(vf); vf->setGeometry(0,0,390,275); vf->show(); cam->start(); }
works.
-
In your version you have two problems:
- You're leaking a QCameraViewFinder each time you click on the button
- Your view finder won't adapt if you change the size of your widget
-
-
Each time you call that function you create a new view finder. It has a parent so it will be destroyed at the end but still, you're filling up memory with unused instances. Either check it has already been created or just create it in the constructor of your widget.
-
You can also use setFixedSize for that.
-
-
@pauledd
Hi.If QMediaPlayer a fixed size then you can solve in a simple way as follows.
like this:
auto mplayer = new QMediaPlayer; auto vw = new QVideoWidget(); auto pal = vw->palette(); // Sets the brush pixmap to pixmap. The style is set to Qt::TexturePattern. pal.setBrush(QPalette::Window, QBrush(QPixmap(":/yourImage.jpg"))); vw->setAutoFillBackground(true); vw->setPalette(pal); mplayer->setMedia(QUrl::fromLocalFile("yourVideo.mp4")); mplayer->setVideoOutput(vw); connect(mplayer, &QMediaPlayer::stateChanged, [vw](QMediaPlayer::State state){ if (state == QMediaPlayer::StoppedState) vw->update(); }); vw->show(); //mplayer->play();
If resizing is enabled will cause a very interesting one. :)
-
thank you for the tip, I will try this in another project since I currently have a lot of problems getting qmediaplayer or qcamera working on the RaspberryPi. I wrote my code on amd64 on which everything worked fine but on the actual device (RPi) a LOT of problems came in (qt-gstreamer-v4l2-bcm2835-v4l2,MMAL, w.t.h.) but thats worth another thread.