Aquí Título de directorio personalizado de escritura
QPropertyAnimation y QVBoxLayout
Una animación personalizada propiedad
1. La figura efecto
En segundo lugar, la idea de construir
cargas verticales disposición de los botones personalizados, paquetes botón de propiedades de animación personalizados. Lograr un alto grado de claves de modificación utilizando Q_PROPERTY (int fixHeight LEER fixHeight WRITE setFixHeight ).
En tercer lugar, los fragmentos de código
#ifndef ANIMATIONBTN_H
#define ANIMATIONBTN_H
#include <QObject>
#include <QWidget>
#include <QPushButton>
#include <QPropertyAnimation>
#include <QSizePolicy>
class animationBtn : public QPushButton
{
Q_OBJECT
Q_PROPERTY(int fixHeight READ fixHeight WRITE setFixHeight)
public:
animationBtn(QWidget* par = nullptr);
~animationBtn();
void start();
void stop();
int fixHeight();
void setFixHeight(int h);
private slots:
void onvalueChanged(QVariant value);
signals:
void BtnHeight(int value);
private:
bool m_stop;
};
#endif // ANIMATIONBTN_H
#include "animationbtn.h"
animationBtn::animationBtn(QWidget *par)
{
resize(this->width(),30);
this->setText("Button");
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
m_stop = false;
}
animationBtn::~animationBtn()
{
}
void animationBtn::start()
{
m_stop = false;
QPropertyAnimation *pAnimation = new QPropertyAnimation(this,"fixHeight");
pAnimation->setStartValue(30);
pAnimation->setEndValue(60);
pAnimation->setDuration(2000);
pAnimation->start(QAbstractAnimation::DeleteWhenStopped);
connect(pAnimation,&QPropertyAnimation::valueChanged,this,&animationBtn::onvalueChanged);
}
void animationBtn::stop()
{
m_stop = true;
}
int animationBtn::fixHeight()
{
return this->height();
}
void animationBtn::setFixHeight(int h)
{
setFixedHeight(h);
}
void animationBtn::onvalueChanged(QVariant value)
{
if(value == 30 && m_stop)
return;
if(value.toInt() == 60){
QPropertyAnimation *pAnimation = new QPropertyAnimation(this,"fixHeight");
pAnimation->setStartValue(60);
pAnimation->setEndValue(30);
pAnimation->setDuration(2000);
pAnimation->start(QAbstractAnimation::DeleteWhenStopped);
connect(pAnimation,&QPropertyAnimation::valueChanged,this,&animationBtn::onvalueChanged);
}
else if(value.toInt() == 30){
QPropertyAnimation *pAnimation = new QPropertyAnimation(this,"fixHeight");
pAnimation->setStartValue(30);
pAnimation->setEndValue(60);
pAnimation->setDuration(2000);
pAnimation->start(QAbstractAnimation::DeleteWhenStopped);
connect(pAnimation,&QPropertyAnimation::valueChanged,this,&animationBtn::onvalueChanged);
}
emit BtnHeight(value.toInt());
}
Bienvenido más intercambios
QQ: 519 096 571
E-mail: [email protected]