How can I implement the desktop with Qt? Snow falls

Source: Internet
Author: User

In the past two days, I have no intention of discovering that someone has written a program such as VC for developing the desktop snowflake program. I have also written a program, so it's just like there's nothing left!

The code is very simple. paste it into the main implementation process. It should support windows and linux Desktop versions, but it will not be tested for now in linux. I am too lazy to restart. I have time to test it.

System resource consumption: I spent about 1.65 GHz dual-core CPU, 4 GB RAM, 32 bit Win7 memory consumption of about 6% m, and about 7%-CPU consumption.

All source code is linked later.

 

# Include widget. h # include ui_widget.h # include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Ifdef Q_ OS _LINUX # include
     
      
# Endif # ifdef Q_ OS _WIN # include
      
        # EndifWidget: Widget (QWidget * parent): QWidget (parent), ui (new Ui: Widget) {ui-> setupUi (this); setGeometry (0, 0, qApp-> desktop ()-> width (), qApp-> desktop ()-> height (); setWindowFlags (windowFlags () | Qt :: framelessWindowHint // border removal | Qt: X11BypassWindowManagerHint // remove from Task Manager in linux | Qt: WindowStaysOnBottomHint // display at the lowest layer | Qt: Tool // not displayed on the taskbar ); setAttribute (Qt: WA_TranslucentBackground); setWindowState (Qt: WindowNoSt Ate // not activated | Qt: WindowFullScreen // full screen); setFocusPolicy (Qt: NoFocus); setWindowOpacity (WINDOW_OPACITY); # ifdef complete (QX11Info: display (), winId (), ShapeInput, 0, 0, NULL, 0, ShapeSet, YXBanded); # endif # ifdef Q_ OS _WINSetWindowLong (winId (), GWL_EXSTYLE, GetWindowLong (winId (), GWL_EXSTYLE) | WS_EX_TRANSPARENT | WS_EX_LAYERED); # endifint I = 0; pixmapList [I ++]. load (:/snowIcons/11.png); PixmapList [I ++]. load (:/snowIcons/03.png); pixmapList [I ++]. load (:/snowIcons/06.png); pixmapList [I ++]. load (:/snowIcons/08.png); pixmapList [I ++]. load (:/snowIcons/10.png); pixmapList [I ++]. load (:/snowIcons/12.png); pixmapList [I ++]. load (:/snowIcons/13.png); pixmapList [I ++]. load (:/snowIcons/16.png); pixmapList [I ++]. load (:/snowIcons/17.png); pixmapList [I ++]. load (:/snowIcons/18.png); pixmapList [I ++]. load (:/snowIco Ns/19.png); for (I = 0; I <MAX_PICS; I ++) {picLabel [I] = new QLabel (this ); picLabel [I]-> setGeometry (-128,-128, 64, 64);} startTimer (150);} Widget ::~ Widget () {delete ui;} void Widget: timerEvent (QTimerEvent * e) {const int timeinit = 10; static int timeCount = timeinit; static int initLabel = MAX_PICS; if (-- timeCount <= 0) {qsrand (: time (NULL); timeCount = timeinit; if (initLabel> 0) {-- initLabel; picLabel [initLabel]-> move (0,-picLabel [initLabel]-> height () ;}} FlashSnow ();} void Widget: SetLabelBG (const QPixmap & pixmap, QLabel * label) {if (! Label | pixmap. isNull () return; QPixmap map = pixmap. scaled (label-> size (); if (map. isNull () return; label-> setPixmap (map);} void Widget: FlashSnow () {int I; for (I = 0; I <MAX_PICS; I ++) {if (picLabel [I] = NULL) continue; if (picLabel [I]-> y () =-picLabel [I]-> height ()) {// resize labelint size = (qrand () % 64) + 16; picLabel [I]-> resize (size, size); // init placeint x = (qrand () % this-> width (); picLabel [I]-> move (x, 10-picLabel [I]-> height (); // repaint label's backgroudint imgId = (qrand () % MAX_PIXMAP); SetLabelBG (pixmapList [imgId], picLabel [I]);} else {// snow flow downWidgetFlowDown (picLabel [I]) ;}} void Widget: WidgetFlowDown (QWidget * widget, bool bRandom) {if (! Widget) return; int downY = widget-> y () + 5; if (bRandom) {downY = widget-> y () + qrand () % (this-> height ()-widget-> y ();} if (downY> (this-> height ())) downY =-widget-> height (); widget-> move (widget-> x (), downY );}
      
     
    
   
  
 

 

Next, let's take a screenshot:

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.