首页下载资源移动开发QT实现弹跳按钮-自定义控件

ZIPQT实现弹跳按钮-自定义控件

u01295947826.91KB需要积分:1

资源文件列表:

BounceButtonDemo.zip 大约有10个文件
  1. BounceButtonDemo/
  2. BounceButtonDemo/bouncebutton.cpp 1.92KB
  3. BounceButtonDemo/bouncebutton.h 366B
  4. BounceButtonDemo/BounceButtonDemo.pro 633B
  5. BounceButtonDemo/main.cpp 172B
  6. BounceButtonDemo/mainwindow.cpp 297B
  7. BounceButtonDemo/mainwindow.h 217B
  8. BounceButtonDemo/res/
  9. BounceButtonDemo/res/StartButton.png 36.79KB
  10. BounceButtonDemo/ui.qrc 98B

资源介绍:

Qt通过重新封装QPushButton类,实现自定义按钮,并且实现点击后的上下跳动特效。
#include "bouncebutton.h" #include #include #include #include #include BounceButton::BounceButton(QString imgPath,QWidget *parent) : QPushButton(parent) { setImage(imgPath); connect(this,&BounceButton::clicked,[=](){this->zoom1();this->zoom2();}); } void BounceButton::zoom1(){ //创建动画对象 QPropertyAnimation *animation1 = new QPropertyAnimation(this,"geometry"); //设置时间间隔,单位毫秒 animation1->setDuration(200); //创建其实位置 animation1->setStartValue(QRect(this->x(),this->y(),this->width(),this->height())); animation1->setEndValue(QRect(this->x(),this->y()+10,this->width(),this->height())); //设置缓和曲线,QEasingCurve::OutBounce 为弹跳效果 animation1->setEasingCurve(QEasingCurve::OutBounce); //开始执行动画 animation1->start(); } void BounceButton::zoom2(){ //创建动画对象 QPropertyAnimation *animation1 = new QPropertyAnimation(this,"geometry"); //设置时间间隔,单位毫秒 animation1->setDuration(200); //创建其实位置 animation1->setStartValue(QRect(this->x(),this->y()+10,this->width(),this->height())); animation1->setEndValue(QRect(this->x(),this->y(),this->width(),this->height())); //设置缓和曲线,QEasingCurve::OutBounce 为弹跳效果 animation1->setEasingCurve(QEasingCurve::OutBounce); //开始执行动画 animation1->start(); } void BounceButton::setImage(QString imgPath) { m_imgPath = imgPath; QPixmap pixmap; bool ret = pixmap.load(m_imgPath); if(!ret) return; //设置图片固定尺寸 this->setFixedSize(pixmap.width(),pixmap.height()); //设置不规则图片的样式表 this->setStyleSheet("QPushButton{border:0px}"); //设置图标 this->setIcon(pixmap); //设置图标大小 this->setIconSize(QSize(pixmap.width(),pixmap.height())); }
100+评论
captcha