Sometimes to do a background processing, but the background processing time is very long, need to prompt the user to wait, may wish to do a dynamic waiting window. The specific implementation process is as follows:
1 Custom window class dlgwait (1) Add a animated GIF image to the resource, remembering its size.
I added is a "loading.gif" picture, size is 100x100, as follows:
(2) Add a window interface class dlgwait
Window size is slightly larger than GIF, such as 150x150
Add 2 Qlabel to the interface:
The first one to display the GIF, named Lbl_gif,text, is empty, and the size is 100x100
The second one, which is used to display the prompt message named lbl_text,text "in background processing, please wait"
As shown below:
(3) Set dlgwait window without border, background transparent effect, and load GIF picture
Add the following code to the Dlgwait constructor:
Setwindowflags (Qt::framelesswindowhint);//No BorderSetAttribute (qt::wa_translucentbackground);//Transparent Background//Center Screen Display intFRMX =width (); intFrmy =height (); Qdesktopwidget W; intDeskwidth =w.width (); intDeskheight =w.height (); Qpoint Movepoint (Deskwidth/2-FRMX/2, Deskheight/2-Frmy/2); Move (Movepoint); //Loading GIF picturesQmovie*movie =NewQmovie (":/img/loading"); UI->lbl_gif->Setmovie (movie); Movie->start ();
2 Use the Wait window
The effect is as follows:
Qt uses Qmovie to load GIF images to implement a dynamic wait window