生活随笔
收集整理的這篇文章主要介紹了
Qt之对话框设计——淡入淡出效果
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
實例化一個QPainter類的窗體對象。首先設置該窗體顯示的最初透明度為255,即不透明;啟動定時器后,以一定的周期重畫該窗體并使窗體的透明度遞減,直至透明度為0,停止定時器,關閉窗體。
fadewidget.h
#ifndef?FADEWIDGET_H??#define?FADEWIDGET_H????#include?<QWidget>????class?QColor;??class?QTimer;????class?FaderWidget?:?public?QWidget??{??????Q_OBJECT????public:??????FaderWidget(QWidget?*parent);????????????void?start();????????protected:??????void?paintEvent(QPaintEvent?*event);????????private:????????QColor?startColor;??????int?currentAlpha;??????int?fadeTimes;??????QTimer?*timer;??};????#endif??//?FADER_H?? fadewidget.cpp
#include?"fadewidget.h"??#include?<QtGui>????FaderWidget::FaderWidget(QWidget?*parent)??????????:?QWidget(parent)??{??????if?(parent)??????????startColor?=?parent->palette().window().color();??????else??????????startColor?=?Qt::white;????????????currentAlpha?=?0;??????fadeTimes?=?1000;????????????timer?=?new?QTimer(this);??????connect(timer,?SIGNAL(timeout()),this,?SLOT(update()));????????????setAttribute(Qt::WA_DeleteOnClose);??????resize(parent->size());??}??????void?FaderWidget::start()??{??????currentAlpha?=?255;??????timer->start(100);??????show();??}????void?FaderWidget::paintEvent(QPaintEvent?*?)??{??????QPainter?painter(this);??????QColor?currentColor?=?startColor;??????currentColor.setAlpha(currentAlpha);??????painter.fillRect(rect(),?currentColor);????????????currentAlpha?-=?255?*?timer->interval()?/?fadeTimes;??????if?(currentAlpha?<=?0)???????{??????????timer->stop();??????????close();??????}??}??
作者:韓兆新 出處:http://hanzhaoxin.cnblogs.com/ 本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。 分類:?[02]Qt語言基礎 標簽:?Qt學習筆記
本文轉自韓兆新博客博客園博客,原文鏈接:http://www.cnblogs.com/hanzhaoxin/archive/2012/11/22/2783222.html,如需轉載請自行聯系原作者
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀
總結
以上是生活随笔為你收集整理的Qt之对话框设计——淡入淡出效果的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。