简单的带动画渐隐效果

来源:互联网 发布:淘宝怎么买vr资源 编辑:程序博客网 时间:2024/04/30 17:12
//tmainwnd.h#ifndef TMAINWND_H#define TMAINWND_H#include <QWidget>#include <QPushButton>class TPushBtn2 : public QPushButton{ Q_OBJECTpublic: explicit TPushBtn2(QWidget *parent = 0); TPushBtn2(const QString &,QWidget *parent = 0); void UpdateAlpha();signals:public slots:protected: void timerEvent(QTimerEvent *e); void enterEvent(QEvent *); void leaveEvent(QEvent *); void changeMe();private: int _alpha; int _alphaTimer; qint8 _nDirection;};class TMainWnd : public QWidget{ Q_OBJECTpublic: explicit TMainWnd(QWidget *parent = 0);signals:public slots:};#endif // TMAINWND_H///tmainwnd.cpp#include <QVBoxLayout>#include <QTimerEvent> #include "tmainwnd.h"TMainWnd::TMainWnd(QWidget *parent) : QWidget(parent){ QVBoxLayout *mainLO = new QVBoxLayout; for(int i = 0 ; i < 10 ; i ++){ TPushBtn2 *btn = new TPushBtn2(tr("Test %1").arg(i)); mainLO->addWidget(btn ); } // style()->drawControl(.drawPushButton(this, paint); setLayout(mainLO);}TPushBtn2::TPushBtn2(QWidget *parent) : QPushButton(parent){}TPushBtn2::TPushBtn2(const QString &text, QWidget *parent) :QPushButton(text,parent),_nDirection(1){}void TPushBtn2::timerEvent(QTimerEvent *e){ changeMe();}void TPushBtn2::enterEvent(QEvent *){ _alpha = 255; _nDirection = 1; changeMe();}void TPushBtn2::leaveEvent(QEvent *){ if(_alphaTimer) killTimer(_alphaTimer); _nDirection = -1; _alphaTimer = startTimer(100);}void TPushBtn2::changeMe(){ _alpha += 45 * _nDirection; QPalette pal =this-> palette(); QColor cr = pal.window().color(); if(_alpha >= 255){ if(_alphaTimer) killTimer(_alphaTimer); _alphaTimer = 0; _alpha = 255 ; } else if( _alpha <= 0) { killTimer(_alphaTimer); _alphaTimer = 0; _alpha = 0 ; } cr.setRed(_alpha); cr.setBlue(_alpha); pal.setColor(QPalette::All,QPalette::Button , cr); this-> setPalette(pal);}////main.cpp#include <QApplication>#include "tmainwnd.h"int main(int argc, char **argv){ QApplication app(argc,argv); TMainWnd window; window.show(); window.resize(800,500); return app.exec();}


 这只是一个粗糙的例子,我只用来测试目的....当然,想要做出真正高光渐隐的效果,例如 QQ 聊天窗口在上面那些工具按钮的高光渐隐效果,有QT 框架的支持 也不是很难的.....只要在 QStyle 里面做的手脚就可以实现了.....
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 一岁宝宝很粘人怎么办 宝宝脸冻了怎么办 婴儿特别粘人怎么办 宝宝说话结巴了怎么办 三岁半宝宝突然口吃怎么办 两岁半宝宝突然口吃怎么办 小孩说话突然结巴怎么办 一岁半宝宝黏人怎么办 2岁宝宝总爱抱怎么办 宝宝受风寒呕吐怎么办 4岁宝宝太粘人怎么办? 宝宝特别黏妈妈怎么办 两岁宝宝总让抱怎么办 两岁宝宝要抱睡怎么办 两岁宝宝老让抱怎么办 孩子说话突然结巴怎么办 6岁幼儿爱哭怎么办 刚上幼儿园爱哭怎么办 四岁宝宝结巴怎么办 孩子突然变结巴怎么办 小孩精神性尿频怎么办 小孩睡觉前尿频怎么办 生僻字打不出来怎么办 名字里有生僻字怎么办 qq语音红包生僻字怎么办 生僻字上不了户口怎么办 7岁儿童结巴怎么办 小孩咳喘有痰怎么办 都说我不爱说话怎么办 宝宝突然结巴了怎么办 淘宝客户不理人怎么办 遇到不说话客户怎么办 同学群没人聊怎么办 群里没人说话怎么办 儿童说话声音沙哑怎么办 孩子不和外人说话怎么办 同学退群该怎么办 宝宝睡觉枕头湿怎么办 一个多月的小宝宝便秘怎么办 小宝宝便秘拉屎困难怎么办 一岁小宝宝便秘怎么办