程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> QT窗口漸現效果,窗口震動效果,鼠標移動窗口,qt漸現

QT窗口漸現效果,窗口震動效果,鼠標移動窗口,qt漸現

編輯:C++入門知識

QT窗口漸現效果,窗口震動效果,鼠標移動窗口,qt漸現


//窗口漸現效果
void MainWindow::closeWindowAnimation() //關閉窗口效果 { 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(); }
//窗口震動效果
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(); }
//鼠標移動窗口效果
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(); }

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved