QLabel label control in the QT is relatively common, it is usually used to display text, of course, its function is not confined to here, you can also use it to display pictures, gif animation, then the next is look at how to do it right;
First, create a new project, add three QLabel controls ui files which are used to display text, images, animation. And then import the resource file to your project, import steps are as follows: Right Project -> then choose to add a new file, the following interface will pop up:
Select Qt-> Qt Resource File can be,
Click Next.
Click the image above image.qrc file, the right will display the following screen:
Click Add - after> to add a prefix, the prefix is generated; and then click Add -> Add files; you can load a local resource file into the project.
Select a photo above, right click -> Copy resource path to the clipboard, so we put the path to the copied resource file; then the rest is a look at how to use these resources in a bar code
#include " mywidget.h " #include " ui_mywidget.h " #include <QMovie> the MyWidget :: the MyWidget (the QWidget * parent): the QWidget (parent), UI ( new new Ui :: the MyWidget) { UI -> setupUi ( the this ) ; // set the text content ui-> labelText-> setText ( " 123 " ); // set the picture ui-> labelImage-> setPixmap (QPixmap ( " : //Image/1.jpg " )); // let the picture Label adaptive size ui-> labelImage->setScaledContents(to true ); // create an animation QMovie * myMovie = new new QMovie ( " : //Image/6.gif " ); // animate ui-> labelGif-> setMovie (myMovie); // animated adaptation ui-> labelGif -> setScaledContents ( to true ); // start the animation myMovie-> start (); } the MyWidget :: ~ the MyWidget () { Delete UI; }
Show results: