-
大小: 3KB文件类型: .7z金币: 1下载: 0 次发布日期: 2021-06-12
- 语言: 其他
- 标签: Qt StackWidget animation 美化
资源简介
QStackedWidget切换widget时的动画
代码片段和文件信息
#include “animationstackedwidget.h“
#include
#include
AnimationStackedWidget::AnimationStackedWidget(QWidget *parent)
: QStackedWidget(parent)
{
m_isAnimating = false;
m_currentValue = 0;
m_currentIndex = 0;
m_previousIndex = 0;
m_animation = new QPropertyAnimation(this QByteArray());
m_animation->setDuration(500);
m_animation->setEasingCurve(QEasingCurve::Linear);
m_animation->setStartValue(0);
m_animation->setEndValue(0);
connect(m_animation SIGNAL(valueChanged(QVariant)) SLOT(valueChanged(QVariant)));
connect(m_animation SIGNAL(finished()) SLOT(animationfinished()));
}
AnimationStackedWidget::~AnimationStackedWidget()
{
delete m_animation;
}
void AnimationStackedWidget::paintEvent(QPaintEvent * event)
{
if(m_isAnimating)
{
QPainter painter(this);
QTransform transform;
renderCurrentWidget(painter transform);
renderPreviousWidget(painter transform);
}
else
{
QWidget::paintEvent(event);
}
}
void AnimationStackedWidget::renderPreviousWidget(QPainter &painter QTransform &transform)
{
QWidget *w = widget(m_previousIndex);
QPixmap pixmap( w->size() );
w->render(&pixmap);
Q_UNUSED(transform);
switch(m_type)
{
case BottomToTop :
{
painter.drawPixmap(0 height()/2 pixmap);
break;
}
case TopToBottom :
{
painter.drawPixmap(0 -height()/2 pixmap);
break;
}
case LeftToRight :
{
painter.drawPixmap(width()/2 0 pixmap);
break;
}
case RightToLeft :
{
painter.drawPixmap(-width()/2 0 pixmap);
break;
}
default: break;
}
}
void AnimationStackedWidget::renderCurrentWidget(QPainter &painter QTransform &transform)
{
QWidget *w = widget(m_currentIndex);
QPixmap pixmap( w->size() );
w->render(&pixmap);
switch(m_type)
{
case BottomToTop :
{
transform.translate(0 m_currentValue);
painter.setTransform(transform);
painter.drawPixmap(0 -height()/2 pixmap);
break;
}
case TopToBottom :
{
transform.translate(0 m_currentValue);
painter.setTransform(transform);
painter.drawPixmap(0 height()/2 pixmap);
break;
}
case LeftToRight :
{
transform.translate(m_currentValue 0);
painter.setTransform(transform);
painter.drawPixmap(-width()/2 0 pixmap);
break;
}
case RightToLeft :
相关资源
- qt网络五子棋
- QWidget实现QDialog的exec方法
- qt_zmq.zip
- 模拟微波炉的桌面小程序qt,qp状态机
- Qt spi测试
- QT自定义多行表头
- QT简单程序源码——猜字游戏
- Qt控件QListWidget实现鼠标拖拽Item换序
- 五子棋棋盘的QT实现
- linux下基于V4L2/Qt的usb摄像头采集显示
- Qt的Excel操作添加了新建Excel文件的功
-
qt/qml MediaPla
yerDemo - Qt编写 - 多功能画图板
- 基于QT实现2048小游戏
- qt model view Delegate的
- QT TableView
- Qt控件的拖放
- qt实现复杂的计算,复杂算法
- QT T9Input
- qtwinmigrate for qt5
- 博客《 Animation动画详解(十)——联
- 带界面简单计算器程序Qt源代码
- Qt5.6.1安装qwt-6.1.2
- Qt版flappy bird
- Qt实现TCP文件传输
- QT 在QLabel上加载图片 并在其上绘制矩
- QT数据库操作实例229050
- Qt5实现拼图+自动寻路
- Qt通讯录可以显示照片完整工程
- Qt5写的猜数字小游戏,注释详细,入
评论
共有 条评论