1 Star 0 Fork 6

yuanmin2100/AnimateStackedWidget

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
animatestackedwidget.cpp 1.69 KB
一键复制 编辑 原始数据 按行查看 历史
zlqzlq 提交于 2022-03-17 20:59 . init commit
#include "animatestackedwidget.h"
#include <QPropertyAnimation>
#include <QParallelAnimationGroup>
#include <QPixmap>
AnimateStackedWidget::AnimateStackedWidget(QWidget *parent) : QStackedWidget(parent)
{
m_label = new QLabel(this);
}
void AnimateStackedWidget::switchIndex(int newIdx)
{
int oldIdx = currentIndex();
if (oldIdx == newIdx || newIdx < 0 || newIdx >= count())
{
return;
}
int w = this->width();
int h = this->height();
QPixmap pixmap = QPixmap::grabWindow(this->winId());
m_label->setPixmap(pixmap);
m_label->setGeometry(0, 0, w, h);
m_label->show();
setCurrentIndex(newIdx);
QPropertyAnimation *animation1 = new QPropertyAnimation(m_label, "pos");
QPropertyAnimation *animation2 = new QPropertyAnimation(currentWidget(), "pos");
animation1->setDuration(500);
animation2->setDuration(500);
animation1->setEasingCurve(QEasingCurve::OutCubic);
animation2->setEasingCurve(QEasingCurve::OutCubic);
if (oldIdx < newIdx) // 󻬶
{
animation1->setStartValue(QPoint(0, 0));
animation1->setEndValue(QPoint(0 - w, 0));
animation2->setStartValue(QPoint(w, 0));
animation2->setEndValue(QPoint(0, 0));
}
else // һ
{
animation1->setStartValue(QPoint(0, 0));
animation1->setEndValue(QPoint(w, 0));
animation2->setStartValue(QPoint(0 - w, 0));
animation2->setEndValue(QPoint(0, 0));
}
QParallelAnimationGroup *group = new QParallelAnimationGroup;
group->addAnimation(animation1);
group->addAnimation(animation2);
group->start(QAbstractAnimation::DeleteWhenStopped);
connect(group, SIGNAL(finished()), m_label, SLOT(hide()));
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yuanmin2100/animate-stacked-widget.git
[email protected]:yuanmin2100/animate-stacked-widget.git
yuanmin2100
animate-stacked-widget
AnimateStackedWidget
master

搜索帮助