QT widget is not visible properly



  • In this code which can able to play video and play *.mp3. code works properly,in my mainwindow.ui I added widget called widgetGif by drag and drop .This widget containing label also. but this widget not visible when I run the program. How can I display this widget called widgetGif

    here is part of my code :

    
        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        #include <QDebug>
        #include <QMovie>
        
        
        MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
            player = new QMediaPlayer(this);
            vw = new QVideoWidget (this);
            player->setVideoOutput(vw);
            this->setCentralWidget(vw); //I think this is the reason
            
            slider = new QSlider(this);
            bar = new QProgressBar(this);
            slider->setOrientation(Qt::Horizontal);
            ui->statusBar->addPermanentWidget(slider);
            ui->statusBar->addPermanentWidget(bar);
            
            
            
            connect(player,&QMediaPlayer::durationChanged,slider,&QSlider::setMaximum);
            connect(player,&QMediaPlayer::positionChanged,slider,&QSlider::setValue);
            connect(slider,&QSlider::sliderMoved,player,&QMediaPlayer::setPosition);
            connect(player,&QMediaPlayer::durationChanged,bar,&QProgressBar::setMaximum);
            connect(player,&QMediaPlayer::positionChanged,bar,&QProgressBar::setValue);
            
            
            sliderVolumn = new QSlider(this);
            sliderVolumn->setOrientation(Qt::Horizontal);
            ui->statusBar->addPermanentWidget(sliderVolumn);
            
            connect(sliderVolumn,&QSlider::sliderMoved,player,&QMediaPlayer::setVolume);
            
            QMovie *movie=new QMovie(":/res/icons/giphy.gif");
            if (!movie->isValid())
            {
                // Something went wrong :(
            }
            ui->labelGif->setMovie(movie);
            movie->start();
            
            ui->widgetGif->setVisible(true);
        }
        
        
        MainWindow::~MainWindow()
        {
            delete ui;
        }
        
        void MainWindow::on_actionOpen_triggered()
        {
            QString filename= QFileDialog::getOpenFileName(this,"Open Folder","","Open a File(*.*)");
            on_actionStop_triggered();
            player->setMedia(QUrl::fromLocalFile(filename));
            on_actionPlay_triggered();
            
            if(filename.endsWith(".mp3")){
                qDebug() << " file is mp3";
                
            }else{
                qDebug() << " not is mp3";
                
            }
        }
    


  • @CorD-SaC Hi,friend. Welcome.

    Could you move below code to void MainWindow::showEvent function, try it.

    QMovie *movie=new QMovie(":/res/icons/giphy.gif");
            if (!movie->isValid())
            {
                // Something went wrong :(
            }
            ui->labelGif->setMovie(movie);
            movie->start();
            
            ui->widgetGif->setVisible(true);
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.