生活随笔
收集整理的這篇文章主要介紹了
类QQ右下角弹出框(Qt)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
使用Qt寫的類QQ右下角彈出框
/***main.cpp
*/
#include <QtGui/QApplication>
#include "dialog.h"int main(int argc, char *argv[])
{QApplication a(argc, argv);Dialog w;w.show();return a.exec();
}/***dialog.h
*/
#ifndef DIALOG_H
#define DIALOG_H#include <QDialog>
#include <QDesktopWidget>
#include <QPropertyAnimation>
#include <QPoint>
#include <QTimer>namespace Ui {
class Dialog;
}class Dialog : public QDialog
{Q_OBJECTpublic:explicit Dialog(QWidget *parent = 0);~Dialog();private:Ui::Dialog *ui;QDesktopWidget desktop;QPropertyAnimation* animation;QTimer *remainTimer;void showAnimation();
private slots:void closeAnimation();void clearAll();
};#endif // DIALOG_H/***
dialog.cpp
*/#include "dialog.h"
#include "ui_dialog.h"
#include <QDebug>Dialog::Dialog(QWidget *parent) :QDialog(parent),ui(new Ui::Dialog)
{ui->setupUi(this);this->setWindowFlags(Qt::FramelessWindowHint); //隱藏菜單欄this->move((desktop.availableGeometry().width()-this->width()),desktop.availableGeometry().height());//初始化位置到右下角showAnimation(); //開始顯示右下角彈出框
}Dialog::~Dialog()
{delete ui;
}
//彈出動畫
void Dialog::showAnimation(){//顯示彈出框動畫animation=new QPropertyAnimation(this,"pos");animation->setDuration(2000);animation->setStartValue(QPoint(this->x(),this->y()));animation->setEndValue(QPoint((desktop.availableGeometry().width()-this->width()),(desktop.availableGeometry().height()-this->height())));animation->start();//設(shè)置彈出框顯示2秒、在彈回去remainTimer=new QTimer();connect(remainTimer,SIGNAL(timeout()),this,SLOT(closeAnimation()));remainTimer->start(4000);//彈出動畫2S,停留2S回去
}
//關(guān)閉動畫
void Dialog::closeAnimation(){//清除Timer指針和信號槽remainTimer->stop();disconnect(remainTimer,SIGNAL(timeout()),this,SLOT(closeAnimation()));delete remainTimer;remainTimer=NULL;//彈出框回去動畫animation->setStartValue(QPoint(this->x(),this->y()));animation->setEndValue(QPoint((desktop.availableGeometry().width()-this->width()),desktop.availableGeometry().height()));animation->start();//彈回動畫完成后清理動畫指針connect(animation,SIGNAL(finished()),this,SLOT(clearAll()));
}
//清理動畫指針
void Dialog::clearAll(){disconnect(animation,SIGNAL(finished()),this,SLOT(clearAll()));delete animation;animation=NULL;
}
轉(zhuǎn)載于:https://my.oschina.net/geekice/blog/162486
總結(jié)
以上是生活随笔為你收集整理的类QQ右下角弹出框(Qt)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。