QT window fade-out effect, window shake effect, mouse move window, qt fade-out
// Window fading effect
Void MainWindow: closeWindowAnimation () // close the window effect {QPropertyAnimation * animation = new QPropertyAnimation (this, "windowOpacity"); animation-> setDuration (500 ); animation-> setStartValue (1); animation-> setEndValue (0); animation-> start (); connect (animation, QPropertyAnimation: finished, this, close );} void MainWindow: startAnimation () {QPropertyAnimation * animation = new QPropertyAnimation (this, "windowOpacity"); animation-> setDuration (500); animation-> setStartValue (0 ); animation-> setEndValue (1); animation-> start ();}
// Window vibration effect
Void MainWindow: shakeWindow () {QPropertyAnimation * animation = new QPropertyAnimation (this, "geometry"); animation-> setDuration (500); animation-> setKeyValueAt (0, QRect (QPoint (this-> frameGeometry (). x ()-3, this-> frameGeometry (). y (), this-> size (); animation-> setKeyValueAt (0.1, QRect (QPoint (this-> frameGeometry (). x () + 6, this-> frameGeometry (). y (), this-> size (); animation-> setKeyValueAt (0.2, QRect (QPoint (this-> frameGeometry (). x ()-6, this-> frameGeometry (). y (), this-> size (); animation-> setKeyValueAt (0.3, QRect (QPoint (this-> frameGeometry (). x () + 6, this-> frameGeometry (). y (), this-> size (); animation-> setKeyValueAt (0.4, QRect (QPoint (this-> frameGeometry (). x ()-6, this-> frameGeometry (). y (), this-> size (); animation-> setKeyValueAt (0.5, QRect (QPoint (this-> frameGeometry (). x () + 6, this-> frameGeometry (). y (), this-> size (); animation-> setKeyValueAt (0.6, QRect (QPoint (this-> frameGeometry (). x ()-6, this-> frameGeometry (). y (), this-> size (); animation-> setKeyValueAt (0.7, QRect (QPoint (this-> frameGeometry (). x () + 6, this-> frameGeometry (). y (), this-> size (); animation-> setKeyValueAt (0.8, QRect (QPoint (this-> frameGeometry (). x ()-6, this-> frameGeometry (). y (), this-> size (); animation-> setKeyValueAt (0.9, QRect (QPoint (this-> frameGeometry (). x () + 6, this-> frameGeometry (). y (), this-> size (); animation-> setKeyValueAt (1, QRect (QPoint (this-> frameGeometry (). x ()-3, this-> frameGeometry (). y (), this-> size (); animation-> start ();}
// Move the mouse over the window
Void MainWindow: mousePressEvent (QMouseEvent * event) {if (event-> button () = Qt: LeftButton) {startPos = event-> globalPos () -this-> frameGeometry (). topLeft (); qDebug () <event-> globalPos () <this-> frameGeometry (). topLeft () <startPos;} else if (event-> button () = Qt: MiddleButton) closeWindowAnimation (); else if (event-> button () ==qt: RightButton) shakeWindow ();} void MainWindow: mouseMoveEvent (QMouseEvent * event) {if (event-> buttons () = Qt :: leftButton & startPos. y () <40) {endPos = event-> globalPos ()-startPos; qDebug () <endPos; this-> move (endPos);} // qDebug () <event-> pos (). x ();}