qt实现轮播图,包含左右切换和选中切换。

qt实现轮播图,包含左右切换和选中切换。

该动画使用到串行动画和并行动画。(该文章包含全部代码)
在这里插入图片描述
大致思路:按钮滚动使用的串行动画,图片滚动使用的并行动画。

#ifndef UANIMAYION_H
#define UANIMAYION_H

#include <QWidget>
#include <QTimer>
#include <QPropertyAnimation>
#include <QSequentialAnimationGroup>
#include <QParallelAnimationGroup>
#include <QLabel>
#include <QPushButton>
#include <QButtonGroup>
#include <QHBoxLayout>

class Uanimayion : public QWidget
{
   
    Q_OBJECT

public:
    explicit Uanimayion(QWidget *parent = nullptr);
    void animation(QString filename);
    void loadbanner();

    ~Uanimayion();
    void deleteAnimation();
signals:

private slots:
    void showPictureSlot();
    void slotbtnclick(int index);
    void onBtnExpvalueChanged(const QVariant &variant);
    void onBtnShrikvalueChanged(const QVariant &variant);
    void slotswithclick();
private:
    QPropertyAnimation* m_frontAnimation;
    QPropertyAnimation* m_backAnimation;
    QPropertyAnimation* m_btnExpAnimation;
    QPropertyAnimation* m_btnShrikAnimation;
    QParallelAnimationGroup* m_groupAnimation;
    QSequentialAnimationGroup* sequentialGroup;

    QTimer* m_qTimer;
    int m_imgNumber;
    int m_curIndex;
    int m_preIndex;
    bool m_blefttoright;
    QStringList m_bannerInfo;

    QLabel* page_front;
    QLabel* page_back;
    QPushButton* m_leftbtn;
    QPushButton* m_rightbtn;
    QButtonGroup* m_buttongroup;
};

#endif // UANIMAYION_H

#include "uanimayion.h"
#include <QCoreApplication>
#include <QDir>
#include <QFileInfo>
#include <QDebug>

const int btn_expand_width = 24;//按钮拉伸宽度
const int btn_shrik_width = 6;//按钮收缩宽度

Uanimayion::Uanimayion(QWidget *parent) : QWidget(parent)
{
   
    m_groupAnimation = NULL;
    m_frontAnimation = NULL;
    m_backAnimation = NULL;
    m_btnExpAnimation = NULL;
    m_btnShrikAnimation = NULL;
    sequentialGroup = NULL;
    m_qTimer = NULL;
    m_imgNumber = 0;
    m_preIndex = 0;
    m_curIndex = 0;
    m_blefttoright = false;
    setAttribute(Qt::WA_TranslucentBackground);
    this->setFixedSize(600,320);

    m_buttongroup = new QButtonGroup(this);
    page_front = new QLabel(this);
    page_back = new QLabel(this);
    page_front->setFixedSize(600,320);
    page_back->setFixedSize(600,320);
    page_front->move(0,0);
    page_back->move(0,0);
    page_front-
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

东方忘忧

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值