麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

QPropertyAnimation 學習筆記7

2019-11-14 09:55:20
字體:
來源:轉載
供稿:網友

QPRopertyAnimation  用于產生動畫效果。

 QPropertyAnimation *animation = new QPropertyAnimation(myWidget, "geometry");  animation->setDuration(10000);  animation->setStartValue(QRect(0, 0, 100, 30));  animation->setEndValue(QRect(250, 250, 100, 30));  animation->start();這是文檔中給出的例子,動畫效果為,將窗口從0,0 位置緩慢移動到250,QPropertyAnimation 用來對Qt屬性進行插值,Qt現在支持的QVariant 類型有QRect,QRectF,QLine,QLineF,QPoint,QColor,int ,double,float等。

這里為一個widget對象的geometry屬性創建動畫。

setDuration 設置動畫時間,ms

setStartValue 設置開始屬性

setEndValue 設置結束屬性

start開始動畫。

除了設置開始屬性和結束屬性外,還可以調用

void QVariantAnimation::setKeyValueAt(qrealstep, const QVariant &value)

在動畫中間設置屬性值。取值范圍為0.0-1.0,0開始,1結束。

其他使用參考文檔。

這里將以一個例子說明如何在實戰中使用:

這是360界面中的三個按鈕,當鼠標進入或離開時,會有動畫效果產生,博客中似乎不能上傳動畫,所以只能提供一張截圖了。

代碼很簡單,也很容易懂,就不多說了。

class mainButton : public QPushButton//用于主的圖片{    Q_OBJECTpublic:    mainButton(QString pixnormal,QString pixenter,QString pixleave,QWidget*parent);    ~mainButton();protected:    void enterEvent(QEvent*);    void leaveEvent(QEvent*);    void paintEvent(QPaintEvent*event);    QPropertyAnimation*m_enteranimation;    QPropertyAnimation*m_leaveanimation;    QList<QPixmap> m_enterlist;    QList<QPixmap> m_leavelist;    QPixmap m_pixnormal;    int m_enterIndex;    int m_leaveIndex;    bool m_enter;    bool m_leave;public slots:    void entervaluechange(QVariant var){m_enterIndex=var.toInt();update();}    void leavevaluechange(QVariant var){m_leaveIndex=var.toInt();update();}};mainButton::mainButton(QString strpixnormal,QString strpixenter,QString strpixleave,QWidget*parent):QPushButton(parent){    QPixmap pixnormal(strpixnormal);    QPixmap pixenter(strpixenter);    QPixmap pixleave(strpixleave);    setCursor(Qt::PointingHandCursor);    m_leave=false;    m_enter=true;    m_leaveIndex=0;    m_enterIndex=0;    m_pixnormal=pixnormal;    for(int i=0;i<10;i++)//進入    {        m_enterlist<<pixenter.copy(i*(pixenter.width()/10),0,pixenter.width()/10,pixenter.height());    }    for(int j=0;j<8;j++)//離開    {        m_leavelist<<pixleave.copy(j*(pixleave.width()/8),0,pixleave.width()/8,pixleave.height());    }    m_enteranimation=new QPropertyAnimation(this,"");    m_enteranimation->setStartValue(0);    m_enteranimation->setEndValue(9);    m_enteranimation->setDuration(600);    connect(m_enteranimation,SIGNAL(valueChanged(QVariant)),this,SLOT(entervaluechange(QVariant)));    m_leaveanimation=new QPropertyAnimation(this,"");    m_leaveanimation->setStartValue(0);    m_leaveanimation->setEndValue(7);    m_leaveanimation->setDuration(600);    connect(m_leaveanimation,SIGNAL(valueChanged(QVariant)),this,SLOT(leavevaluechange(QVariant)));}mainButton::~mainButton(){    delete m_leaveanimation;    delete m_enteranimation;}void mainButton::enterEvent(QEvent *){    m_enter=true;    m_leave=false;    m_enteranimation->start();}void mainButton::leaveEvent(QEvent *){    m_enter=false;    m_leave=true;    m_leaveanimation->start();}void mainButton::paintEvent(QPaintEvent *event){    QPainter painter(this);    if(m_enter)    painter.drawPixmap(rect(),m_enterlist.at(m_enterIndex));    if(m_leave)    painter.drawPixmap(rect(),m_leavelist.at(m_leaveIndex));}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 毛片在线免费 | 欧美五月婷婷 | 久久久成人精品 | 欧美色视频免费 | 国产精品视频一区二区噜噜 | 亚洲一区久久 | 国产免费久久久久 | 久久久三级免费电影 | 偿还电影免费 | 成人性视频在线 | 久久久免费 | 一级黄色影片在线观看 | 欧美一级黄色免费看 | 亚洲精品一区二区三区在线看 | 91在线免费观看 | 日本残忍极度灌浣肠视频 | 自拍偷拍999 | 深夜福利久久久 | 中文字幕一二区 | 成人一级黄色大片 | 欧美三级短视频 | 欧美日韩在线免费观看 | 日韩视频一区二区三区四区 | 9191久久久久视频 | 轻点插视频 | 久国久产久精永久网页 | 国产1区在线观看 | 成人 日韩 | 国产精品久久久久久久久久10秀 | 久久精国 | 欧美成人影院 | 2021免费日韩视频网 | 一区二区三区视频在线观看 | 日本免费一区二区三区四区 | 依依成人精品视频 | 亚洲成人福利在线观看 | 成人综合免费视频 | 亚洲第一成网站 | 精品亚洲va在线va天堂资源站 | 黄色毛片a级 | 亚洲欧美日韩中文在线 |