Implement window Jitter

Source: Internet
Author: User

The sending window jitter function is available in QQ and other chat software, which is now available in QT.

The main classes used are:QtimerAndQpoint

The qtimer class is used to enable the timer and place the window in different positions at different times. The effect is the jitter of the window. The qpoint class is used to locate the position (coordinates) of the window ).

The source code is as follows:

// Chardialog. h # ifndef chatdialog_h # define chatdialog_h # include <qdialog> namespace UI {class chatdialog;} class chatdialog: Public qdialog {q_object public: explicit chatdialog (personlogininfo * pb, qwidget * parent = 0 );~ Chatdialog (); Private: Ui: chatdialog * UI; private: qtimer * m_timer; int counter; qpoint curpos; Enum {maxlimittimes = 500 }; // Number of jitter Enum {maxlimitspace = 20}; // jitter amplitude Enum {shakespeed = 1000}; // jitter speed private slots: void s_timeout (); void slotshakewindow () ;}; # endif // chatdialog_h

// Chatdialog. CPP # include "chatdialog. H "# include" ui_chatdialog.h "chatdialog: chatdialog (personlogininfo * pb, qwidget * parent): qdialog (parent), UI (new UI: chatdialog) {UI-> setupui (this); m_timer = new qtimer (this); Connect (m_timer, signal (timeout (), this, slot (s_timeout ())); connect (ui-> shakewindow, signal (clicked (), this, slot (slotshakewindow (); counter = maxlimittimes;} void chatdialog: s_timeout () {If (counter <maxlimittimes) // No jitter ends {++ counter; Switch (counter % 4) {Case 1: {qpoint tmppos (curpos. X (), curpos. Y ()-maxlimitspace); this-> move (tmppos);} break; Case 2: {qpoint tmppos (curpos. X ()-maxlimitspace, curpos. Y ()-maxlimitspace); this-> move (tmppos);} break; Case 3: {qpoint tmppos (curpos. X ()-maxlimitspace, curpos. Y (); this-> move (tmppos);} break; Case 0: Default: This-> move (curpos); break ;}} else {m_timer-> stop () ;}} void chatdialog: slotshakewindow () {counter = 0; curpos = This-> pos (); m_timer-> Start (shakespeed );}

Message: I am a student, and I know nothing about it.

2014-07-24 03:21:53

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.