国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

QPropertyAnimation 學(xué)習(xí)筆記7

2019-11-14 09:55:20
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

QPRopertyAnimation  用于產(chǎn)生動(dòng)畫(huà)效果。

 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();這是文檔中給出的例子,動(dòng)畫(huà)效果為,將窗口從0,0 位置緩慢移動(dòng)到250,QPropertyAnimation 用來(lái)對(duì)Qt屬性進(jìn)行插值,Qt現(xiàn)在支持的QVariant 類(lèi)型有QRect,QRectF,QLine,QLineF,QPoint,QColor,int ,double,float等。

這里為一個(gè)widget對(duì)象的geometry屬性創(chuàng)建動(dòng)畫(huà)。

setDuration 設(shè)置動(dòng)畫(huà)時(shí)間,ms

setStartValue 設(shè)置開(kāi)始屬性

setEndValue 設(shè)置結(jié)束屬性

start開(kāi)始動(dòng)畫(huà)。

除了設(shè)置開(kāi)始屬性和結(jié)束屬性外,還可以調(diào)用

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

在動(dòng)畫(huà)中間設(shè)置屬性值。取值范圍為0.0-1.0,0開(kāi)始,1結(jié)束。

其他使用參考文檔。

這里將以一個(gè)例子說(shuō)明如何在實(shí)戰(zhàn)中使用:

這是360界面中的三個(gè)按鈕,當(dāng)鼠標(biāo)進(jìn)入或離開(kāi)時(shí),會(huì)有動(dòng)畫(huà)效果產(chǎn)生,博客中似乎不能上傳動(dòng)畫(huà),所以只能提供一張截圖了。

代碼很簡(jiǎn)單,也很容易懂,就不多說(shuō)了。

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++)//進(jìn)入    {        m_enterlist<<pixenter.copy(i*(pixenter.width()/10),0,pixenter.width()/10,pixenter.height());    }    for(int j=0;j<8;j++)//離開(kāi)    {        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));}


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 洛浦县| 大同市| 峨山| 灵宝市| 宣武区| 固阳县| 永靖县| 广平县| 于田县| 中西区| 木里| 南通市| 万源市| 清水县| 鄂托克旗| 马鞍山市| 阿克| 峨眉山市| 鲁甸县| 罗山县| 武义县| 永春县| 宁安市| 内丘县| 临朐县| 西藏| 诏安县| 湛江市| 垫江县| 琼中| 绍兴市| 许昌县| 合作市| 太白县| 乳山市| 普定县| 临澧县| 海原县| 莱西市| 玛多县| 抚松县|