简单的带动画渐隐效果

    
    
// tmainwnd.h #ifndef TMAINWND_H #define TMAINWND_H #include < QWidget > #include < QPushButton > class TPushBtn2 : public QPushButton { Q_OBJECT public : 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_OBJECT public : 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 里面做的手脚就可以实现了.....
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值