QPropertyAnimation 学习笔记7

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(qreal step, const QVariant &value)

在动画中间设置属性值。取值范围为0.0-1.0,0开始,1结束。

其他使用参考文档。


这里将以一个例子说明如何在实战中使用:

这是360界面中的三个按钮,当鼠标进入或离开时,会有动画效果产生,博客中似乎不能上传动画,所以只能提供一张截图了。



代码很简单,也很容易懂,就不多说了。

class mainButton : public QPushButton//用于主的图片
{
    Q_OBJECT
public:
    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));
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
本篇笔记主要介绍JSP中的EL表达式和JSTL标签库。 一、EL表达式(Expression Language) EL表达式是JSP中一个非常重要的特性,它可以在JSP页面中方便地访问JavaBean中的属性和方法,同时还可以进行一些简单的运算操作。EL表达式的语法非常简单,使用${}表示。例如,我们可以通过${user.name}访问一个名为user的JavaBean中的name属性。 EL表达式支持许多运算符,如算数运算符(+、-、*、/、%)、比较运算符(>、<、>=、<=、==、!=)、逻辑运算符(&&、||、!)等等,还支持一些特殊的运算符,如“empty”用于判断一个对象是否为空,如${empty user}表示判断user对象是否为空。 二、JSTL标签库(JSP Standard Tag Library) JSTL是JSP标准标签库,提供了一组标签和函数,可以方便地实现一些常见的任务,如迭代、条件判断、格式化等等。JSTL标签库包含五个核心标签库: 1.核心标签库(Core Tag Library):提供了一些基本的标签,如if、forEach等等。 2.格式化标签库(Formatting Tag Library):提供了一些标签,用于格式化日期、数字等等。 3.SQL标签库(SQL Tag Library):提供了一些标签,用于执行SQL查询和更新操作。 4.XML标签库(XML Tag Library):提供了一些标签,用于处理XML文档。 5.函数标签库(Functions Tag Library):提供了一些函数,可以用于字符串处理、日期处理等等。 使用JSTL标签库需要在JSP页面中引入相应的标签库,例如: ``` <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> ``` 其中,prefix表示标签库的前缀,uri表示标签库的统一资源标识符(URI)。 使用JSTL标签库的语法和EL表达式类似,也是使用${}来引用JavaBean中的属性和方法,同时可以使用JSTL标签来实现一些复杂的逻辑。例如,可以使用<c:if>标签来实现条件判断,如: ``` <c:if test="${user.age > 18}"> <p>成年人</p> </c:if> ``` 以上就是本篇笔记的全部内容,EL表达式和JSTL标签库是JSP中非常重要的特性,掌握它们可以让我们更加方便地开发JSP应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值