zoukankan      html  css  js  c++  java
  • 一个QT 3D转动控件

    其实说到底就是不停的截图,做出的幻觉。联想起360拖动图片,也是合并图片做出的效果,可见的对GUI来说图片是一切,是最根本的解决一切问题的办法,编程仅是辅助实现手段而已,我要记住这一点。

    .h文件

    #ifndef WIDGET1_H
    #define WIDGET1_H
    
    #include <QVariant>
    #include <QWidget>
    #include <QLabel>
    #include <QStackedWidget>
    class RotatingStackedWidget : public QStackedWidget
    {
        Q_OBJECT
    
        Q_PROPERTY( float rotateVal READ rotateVal WRITE setRotateVal);
        public:
            explicit RotatingStackedWidget(QWidget *parent = 0);
            void paintEvent(QPaintEvent *);
            void rotate(int);
    
            float rotateVal();
            void setRotateVal(float);
    
        signals:
    
        private slots:
            void valChanged(QVariant);
            void animDone();
        private:
            float iRotateVal;
    
            bool isAnimating;
            int nextIndex;
    };
    
    #endif // WIDGET1_H

    .cpp文件:

    #include "RotatingStackedWidget.h"
    #include <QPixmap>
    #include <QVBoxLayout>
    #include <QPainter>
    #include <QTransform>
    #include <QPropertyAnimation>
    #include <QParallelAnimationGroup>
    #include <QDebug>
    
    
    RotatingStackedWidget::RotatingStackedWidget(QWidget *parent) :
        QStackedWidget(parent)
    {
        iRotateVal=0;
        isAnimating=false;
    }
    void RotatingStackedWidget::paintEvent(QPaintEvent * event)
    {
        if(isAnimating)
        {
            if(iRotateVal > 90)
            {
                QPixmap pixmap(widget(nextIndex)->size());
                widget(nextIndex)->render(&pixmap);
                QPainter painter(this);
    
                QTransform transform;
                transform.translate(width()/2, 0);
                transform.rotate(iRotateVal+180,Qt::YAxis);
                painter.setTransform(transform);
                painter.drawPixmap(-1*width()/2,0,pixmap);
            }
            else
            {
                QPixmap pixmap(currentWidget()->size());
                currentWidget()->render(&pixmap);
                QPainter painter(this);
    
                QTransform transform;
                     transform.translate(width()/2, 0);
                     transform.rotate(iRotateVal,Qt::YAxis);
                     painter.setTransform(transform);
                painter.drawPixmap(-1*width()/2,0,pixmap);
            }
        }
        else
        {
            QWidget::paintEvent(event);
        }
    }
    
    void RotatingStackedWidget::rotate(int index)
    {
        if(isAnimating)
            return;
    
        nextIndex = index;
    
        int offsetx=frameRect().width();
        int offsety=frameRect().height();
    
    
        widget(index)->setGeometry ( 0,  0, offsetx, offsety );
    
        QPropertyAnimation *animnow = new QPropertyAnimation(this,"rotateVal");
    
        animnow->setDuration(500);
        animnow->setEasingCurve(QEasingCurve::Linear);
        animnow->setStartValue(0);
        animnow->setEndValue(180);
        connect(animnow,SIGNAL(valueChanged(QVariant)),this,SLOT(valChanged(QVariant)));
        connect(animnow,SIGNAL(finished()),this,SLOT(animDone()));
    
        currentWidget()->hide();
    
        isAnimating = true;
        animnow->start();;
    }
    
    
    float RotatingStackedWidget::rotateVal()
    {
        return iRotateVal;
    }
    void RotatingStackedWidget::setRotateVal(float fl)
    {
        iRotateVal = fl;
    }
    
    
    void RotatingStackedWidget::valChanged(QVariant)
    {
        repaint();
    }
    
    void RotatingStackedWidget::animDone()
    {
        iRotateVal=0;
        isAnimating=false;
        widget(nextIndex)->show();
        widget(nextIndex)->raise();;
        setCurrentWidget(widget(nextIndex));
        repaint();
    
    }

    参考:https://github.com/jun-zhang/Qt-Rotating-Widget

  • 相关阅读:
    [转]IIS 6.0中配置HTTP Gzip压缩
    SmartPhone下解决rm、rmvb等格式电影播放的方案(参考意见)
    提取文件夹下所有文件,按类型进行提取
    重学JSP—设置CATALINA_HOME环境变量
    android学习笔记
    用myeclipse配置hibernate
    Java 回调函数 转自:http://blog.sina.com.cn/s/blog_48cf38890100go6x.html
    fastadmin单独控制编辑、删除按钮的展示和隐藏
    fastadmin导出图片
    php计算坐标距离
  • 原文地址:https://www.cnblogs.com/findumars/p/4711391.html
Copyright © 2011-2022 走看看