How to close video widget window once video is done playing QVideoWidget? - c++

I want to display a video when a button is clicked and close the video widget once the video is done playing in QT 6.4, and if there is no workaround that, if I could somehow display the video in a widget I create on QTDesigner that would work well too, thank you!
QMediaPlayer* player = new QMediaPlayer;
player->setSource(QUrl("C:/Users/QTDev/Desktop/final.mp4"));
QAudioOutput * audioOutput = new QAudioOutput;
player->setAudioOutput(audioOutput);
audioOutput->setVolume(1.0);
QVideoWidget* videoWidget = new QVideoWidget;
player->setVideoOutput(videoWidget);
videoWidget->showFullScreen();
player->play();

Related

How do I use paintEvent on a QVideoWidget with transparency?

I'm working on qt5 (C +).
I use QVideoWidget to play rtsp video stream. I wanted to draw any signatures with QPainter on the displayed video. However, I obscure the video while drawing. For example, as for the drawing area, I have given half of the QVideoWidget image.
example used:
Tried adding an extra QLabel on QVideoWidget:
QLabel * label = new QLabel (ui-> videoWidget);
And then draw on the "label", but also cover the QVideoWidget.
I also added:
ui-> videoWidget-> setAttribute (Qt :: WA_X11OpenGLOverlay);
But then the transparency extends all the way to the desktop of the operating system.
Try to set the transparency of the item that you want to draw and not the transparency of the QVideoWidget.

Focus not seen in Qt for Qdial subclass

I am using Qt in Visual Studio to get an interface with buttons and knobs etc. I am using this SkinnedDial class - http://dronecolony.com/2012/12/11/customized-qdial-with-qss-support/ , to get a QDial with a custom image. But the problem is that while the other controls are showing the focus frame when I tab over them, this control does not show the focus - for instance button shows the rectangle, but nothing shows up for the dial. Here's the code segment for the dial -
SkinnedDial *myDial;
...
myDial = new SkinnedDial(this);
myDial->setRange(-100, 100);
QPixmap *bg = new QPixmap();
bg->load("C:/Current/dial.png");
QPixmap *nl = new QPixmap();
nl->load("C:/Current/needl.png");
myDial->setBackgroundImage(*bg);
myDial->setNeedleImage(*nl);
myDial->setMaxAngle(100);
I am new to Qt and C++ and I'm not sure how to solve this problem.

How to customize the loading screen in Qt?

I need to create a customized and animated loading screen in Qt, and I don't need a progress bar.
I want to do something like this:
Anyone knows how can I do that?
Can I use, for example, QSplashScreen?
Try QMovie to load an animation`
QMovie * movie = new QMovie("http://i.stack.imgur.com/vdYAH.gif");
You can either load the movie directly to a label, hide and show it when necessary
QLabel label;
label.setMovie(movie);
movie->start();
Or read the frames of the movie to set splash screen pixmap continuously
connect(movie, SIGNAL(frameChanged(int)), this, SLOT(setSplashScreenPixmap(int)));
movie->start();

Qt - How to show gif(animated) image in QGraphicsPixmapItem

I am trying to use one blinking image in QGraphicsPixmapItem. The image has shown without the animation effect. The below is the original image, the following is the QGraphicsScene which uses this image in QGraphicsPixmapItem. Can anybody say how to achieve this?.
use this code
QGraphicsScene scene;
QLabel *gif_anim = new QLabel();
QMovie *movie = new QMovie(image);
gif_anim->setMovie(movie);
movie->start();
QGraphicsProxyWidget *proxy = scene.addWidget(gif_anim);

Is it possible to have an animated QSystemTrayIcon?

I can't seem to find any info about this. but a lot of kde apps use animated icons.
As i know it setting as QIcon a gif won't work, as only first frame will be displayed.
I didn't try this but it is probably possible by setting new icon every few milliseconds.
/* list of frames */
QLinkedList<QIcon> frames;
/* frames are icons created from images in application resources */
frames <&lt QIcon(":/images/icon1.png") <&lt QIcon(":/images/icon2.png");
/* set timer */
QTimer timer = new QTimer(this);
timer->setSingleShot(false);
connect(timer, SIGNAL(timeout()), this, SLOT(updateTrayIcon()));
timer->start(500); /* update icon every 500 milliseconds */
/*
updateTrayIcon function (SLOT) sets next tray icon
(i.e. iterates through QLinkedList frames)
*/
I suppose that you have two ways:
Try to use GIF animated file (start playing with GIF with QMovie), and place it to the tray (i'm not sure about this case)
The other way is to use QTimer and a few different images. Here I found an example.
I did like this:
QMovie *movie = new QMovie(":/icons/icon.gif");
QLabel *label = new QLabel(this);
label->setMovie(movie);
movie->start();
QTimer *timer = new QTimer(this);
timer->setSingleShot(false);
connect(timer, &QTimer::timeout, [this,timer,label](){
trIcon->setIcon(label->movie()->currentPixmap());
timer->start(50);
});
timer->start(50);