setWindowTitle(QStringLiteral("缩放动画@Qt君")); w->resize(320, 240); QLabel *label = new QLabel(w); /* 创建一个动画对象 */ QPropertyAnimation *animation = new QPropertyAnimation(label); /* 设置动画持续时长 */ animation->setDuration(3000); /* 设置动画目标 君")); w->resize(320, 240); QLabel *label = new QLabel(w); label->resize(100, 100); /* 创建一个动画对象 */ QPropertyAnimation *animation = new QPropertyAnimation(label); /* 设置动画目标 */ animation->setTargetObject(label); /* 设置窗口的位置作为动画参考 *animation= new QPropertyAnimation(label); /* 设置动画目标 */ animation->setTargetObject(opacityEffect);
简述:QPropertyAnimation (动画类,用来向QObject对象添加动画) 该类的继承框图如下所示: ? 1.QAbstractAnimation(所有动画的抽象基类) 该抽象类为QPropertyAnimation提供了动画播放,暂停,停止,持续时间,循环周期等抽象函数. (用来向QObject对象添加动画属性) 该类的构造函数如下所示: QPropertyAnimation(QObject *target, const QByteArray &propertyName 省略其它动画初始化 CloseAnimation = new QPropertyAnimation(this,"geometry",this); CloseAnimation->setDuration //图标下浮动画 LogoDownAnimation = new QPropertyAnimation(logo,"geometry",this); LogoDownAnimation-
实现动画的效果: void Dialog::initAnim() { QPropertyAnimation *m_upMainAnimation = new QPropertyAnimation *m_downMainAnimation = new QPropertyAnimation(m_bottomWidget, "pos"); m_downMainAnimation->setDuration m_upGroup->addAnimation(m_upMainAnimation); m_upGroup->addAnimation(m_downMainAnimation); QPropertyAnimation *m_upGarAnimation = new QPropertyAnimation(m_topWidget, "pos"); m_upGarAnimation->setDuration(400 *m_downGarAnimation = new QPropertyAnimation(m_bottomWidget, "pos"); m_downGarAnimation->setDuration
Pixel_per_second*0.2*(300/ms); if(moveValue > scrollV_max) { moveValue = scrollV_max; } } 最后再调用QPropertyAnimation CustomScroll_H #include <QObject> #include <QWidget> #include <QTimer> #include <QTableView> #include <QPropertyAnimation m_scrollTimer; QTimer m_selectTimer; QTableView *m_table; QScrollBar *m_scrollBar; QPropertyAnimation this); m_table->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); animation = new QPropertyAnimation
widget) widget.setGeometry(QRect(0, 0, 100, 100)) # 绑定组件和属性 self.animation = QPropertyAnimation self.animation_group = QSequentialAnimationGroup() # 绑定组件和属性 # 正向 animation = QPropertyAnimation animation.start() self.animation_group.addAnimation(animation) # 反向 animation = QPropertyAnimation 这时我们可以重载 QPropertyAnimation 来实现我们的需求。 #-*- coding: utf-8 -* __author__ = 'geebos' from PyQt5.Qt import * class PropertyAnimation(QPropertyAnimation
QGraphicsOpacityEffect(); m_button->setGraphicsEffect(effect); effect->setOpacity(0); m_animation = new QPropertyAnimation HIDESHOWLISTVIEW_H #include <QObject> #include <QSize> QT_BEGIN_NAMESPACE class QPushButton; class QPropertyAnimation private: int m_timerId=-1; QWidget*m_list; QPushButton *m_button; QWidget *m_parent; QPropertyAnimation QEvent> #include <QPushButton> #include <QStringLiteral> #include <QWidget> #include <QDebug> #include <QPropertyAnimation QGraphicsOpacityEffect(); m_button->setGraphicsEffect(effect); effect->setOpacity(0); m_animation = new QPropertyAnimation
import sys from PyQt5.QtCore import Qt, QPropertyAnimation, QRect, pyqtProperty, pyqtSignal from PyQt5 _switch_animation = QPropertyAnimation(self, b"switchRect", self) self. _switch_animation.setDirection(QPropertyAnimation.Forward if not self. _switch_on else QPropertyAnimation.Backward) self.
Qt提供了几种属性动画类,如QPropertyAnimation、QVariantAnimation、QParallelAnimationGroup和QSequentialAnimationGroup等 return a.exec();}4.mainwindow.h:#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>#include <QPropertyAnimation nullptr); ~MainWindow();private slots: void startAnimation();private: Ui::MainWindow *ui; QPropertyAnimation MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) , animation(new QPropertyAnimation
动画Qt 通过 QPropertyAnimation、QSequentialAnimationGroup 和 QParallelAnimationGroup 等类支持动画效果。 示例代码:#include <QApplication>#include <QWidget>#include <QPushButton>#include <QPropertyAnimation>class QApplication app(argc, argv); AnimatedWidget widget; widget.resize(200, 200); widget.show(); QPropertyAnimation *animation = new QPropertyAnimation(&widget, "opacity"); animation->setDuration(1000); animation
我们将首先看Robot类,以了解如何组装不同的部分,以便可以使用QPropertyAnimation分别旋转和动画化各个部分,然后我们将看ColorItem类,以演示如何在项目之间实现拖放。 QGraphicsObject通过继承QObject提供信号和槽,它还可使用Q_PROPERTY声明QGraphicsItem的属性,这使该属性可用于QPropertyAnimation。 ->setEndValue(-20); QPropertyAnimation *headScaleAnimation = new QPropertyAnimation(headItem, "scale 这两个QPropertyAnimation实例仅设置对象,属性以及各自的开始和结束值。 所有动画均由一个顶级并行动画组控制。比例和旋转动画已添加到该组中。其余动画以类似方式定义。 for (int i = 0; i < animation->animationCount(); ++i) { QPropertyAnimation *anim = qobject_cast
<QWidget> class QLabel; class QHBoxLayout; class QSpacerItem; class QParallelAnimationGroup; class QPropertyAnimation QWidget *widgetNav; //存放导航指示器的容器 //动画切换 QParallelAnimationGroup *animationGroup; QPropertyAnimation *animationImage; QPropertyAnimation *animationMin; QPropertyAnimation *animationMax; private 定义动画组 animationGroup = new QParallelAnimationGroup(this); //定义动画切换图片 animationImage = new QPropertyAnimation QEasingCurve::OutCubic); animationMin->setDuration(500); //用于切换最大拉伸宽度 animationMax = new QPropertyAnimation
把继承的父亲Widget改为QPushButton,总共改了三处 在mB.cpp中添加实现: #include "mypushbutton.h"#include <QDebug>#include <QPropertyAnimation this->setIconSize(QSize(pix.width(),pix.height())); } //向上弹跳 void myPushButton::zoom1() { QPropertyAnimation *animaltion=new QPropertyAnimation(this,"geometry"); //设置动画时间间隔 animaltion->setDuration(200) QEasingCurve::OutBounce); //开始执行动画 animaltion->start(); } void myPushButton::zoom2() { QPropertyAnimation *animaltion=new QPropertyAnimation(this,"geometry"); //设置动画时间间隔 animaltion->setDuration(200)
画表针 */ } 另一个的实现,文末有引用,感谢 #ifndef GAUGEPANEL_H #define GAUGEPANEL_H #include <QWidget> #include <QPropertyAnimation = QColor(100, 180, 255, 80); colorHaloEnd = QColor(30, 80, 120, 20); hShearAnimation = new QPropertyAnimation (this, "hShearValue"); vShearAnimation = new QPropertyAnimation(this, "vShearValue"); //setWindowFlags = QPropertyAnimation::Stopped){ hShearAnimation->stop(); } if(vShearAnimation->state = QPropertyAnimation::Stopped){ vShearAnimation->stop(); } hShearAnimation->setDuration
include <QWidget> #include <QStackedWidget> #include <QAbstractScrollArea> #include <QPixmap> #include <QPropertyAnimation SWITCH_NONE; QWidget *m_parent; QWidget m_smoothWidget; int m_smoothCurrentIndex=-1; QPropertyAnimation
PyQt5.QtCore import * from PyQt5.QtWidgets import * from PyQt5.QtGui import * self.listView_Anim = QPropertyAnimation
setScaledContents(true); m_pLoadingLabel->setMovie(pMovie); pMovie->start(); 更多参考 Qt之等待提示框(QTimer) Qt之等待提示框(QPropertyAnimation
切换图片的时候可以带上动画过渡或者切换效果,显得更人性化,其实主要还是炫一些,比如百叶窗、透明度变化、左下角飞入等,无论多少种效果,核心都是围绕QPainter来进行,将各种动画效果对应的图片的区域动态计算并绘制出来,配合以QPropertyAnimation MoveBottomToLeftUpEffect = 8//图像1不动,同时图像2从右下到左上 * 2:可设置两张图片的路径名称或者图片 * 3:可设置动画因子 */ #include <QWidget> class QPropertyAnimation //图片1 QPixmap pixmap2; //图片2 AnimationType animationType; //动画效果类型 QPropertyAnimation
PyQt5.QtCore中的 QPropertyAnimation可以实现动画功能。 下面第一个例子通过将一个QLabel对象移动和放大来实现简单的动画: ? import sysfrom PyQt5.QtCore import QPropertyAnimation, QRect, QEasingCurvefrom PyQt5 import QtGuifrom self.label.setPixmap(pixmap) self.label.setGeometry(0, 0, 300, 300) self.animation = QPropertyAnimation _pas = [] for i in range(stickManNodeCount): pa = QtCore.QPropertyAnimation(self.m_stickMan.node
鼠标在控件上方 :pressed 该控件被按下时的状态 :disabled 该控件禁用时的状态 :first 该控件是第一个(列表中) :focus 该控件有输入焦点时 动画 QPropertyAnimation //winLabel 你要对那个组件使用动画 geometry几何结构 QPropertyAnimation * an = new QPropertyAnimation(winLabel,”geometry
进度仪表盘主要应用场景是标识一个任务进度完成的状况等,可以自由的设置范围值和当前值,为了美观还提供了四种指示器(圆形指示器/指针指示器/圆角指针指示器/三角形指示器),各种颜色都可以设置,其中的动画效果采用的QPropertyAnimation 8:支持鼠标进入和离开动画效果 * 9:可设置是否显示当前值 * 10:可设置是否显示指示器 */ #include <QWidget> #include <QVariant> class QPropertyAnimation //是否鼠标悬停 int radiusCoverCircle; //覆盖圆半径 int radiusCircle; //中间圆半径 QPropertyAnimation