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

background



  • someone please tell me that how to set a gif image on my centralwidget


  • Lifetime Qt Champion

    Hi
    Just put a Qlabel there and set the GIF via setPixmap
    If you mean an animated gif, have a look at QMovie.
    https://doc.qt.io/qt-5/qmovie.html

    alt text

    You can also set it to central with

        QPixmap pix(":/test.gif"); // note this is from an ressource file    
         QLabel *label = new QLabel;    
          label->setPixmap(pix);    
          label->setScaledContents(true);    
          setCentralWidget(label);
    

    alt text



  • Thanks alot sir



  • Ah!! sir one more thing i want set an animated gif on the background and i was able to do it with the help of qmovie on qlabel but when i want to add a pushbutton or anything else it doesn't appear on the screenAnnotation 2019-10-08 064225.png

    after running i got this
    Annotation 2019-10-08 064327.png
    you see there is no pushbutton on main form

    the code i have written is
    ```
    *this->setCentralWidget(ui->label);
    QMovie movie = new QMovie(":/Images/7T9364v.gif");
    ui->label->setMovie(movie);
    movie->start();
    ui->label->setScaledContents(true);



  • Think about what would be required to allow pushbuttons over top of an animated image. every time the background image frame is updated, all the higher z-order widgets would need to be checked and potentially repainted. From a programmatic perspective I would avoid adding widgets over top of an animation.

    You also need to consider that the animation and buttons are part of the same layout. If you really want buttons on an animation, shouldn't those buttons be children of the image, instead of peers in the parent layout?


Log in to reply