Qt 오른쪽 하단 팝 업 상자 만 들 기

2779 단어 LinuxQt
Qt 의 오른쪽 하단 팝 업 상자, 토론 환영
이 예 는 주로 QProperty Animation 을 애니메이션 클래스 로 사용 합 니 다.
코드 를 직접 올 리 면 설명 이 잘 들 리 겠 지만,
소스 코드 다운로드 주소:http://download.csdn.net/detail/silencesu/4583309 
main.cpp
#include 
#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 
#include 
#include 
#include 
#include 

namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
    Q_OBJECT
    
public:
    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 

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();

    //       2 、    
    remainTimer=new QTimer();
    connect(remainTimer,SIGNAL(timeout()),this,SLOT(closeAnimation()));
    remainTimer->start(4000);//    2S,  2S  
}
//    
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;
}

좋은 웹페이지 즐겨찾기