Qt/C++ 360安全卫士主界面动态按钮demo
2016-05-31 01:44
513 查看
一,先上最终效果图
由于制不来gif就只能传个hover状态的了,所以看不出实际效果了
二,主要代码:
1.头文件
#include<QObject>
.cpp文件
#include"my360button.h"
三,demo下载:http://download.csdn.net/detail/what951006/9535965
powered by 小乌龟在大乌龟背上
更多文章:http://blog.csdn.net/what951006
由于制不来gif就只能传个hover状态的了,所以看不出实际效果了
二,主要代码:
1.头文件
#include<QObject>
#include <QWidget>
#include<QPaintEvent>
#include<QEvent>
#include<QPushButton>
#include<qpropertyanimation.h>
#include<QDebug>
class my360button : public QPushButton
{
Q_OBJECT
public:
my360button(QPixmap pixnormal,QPixmap pixenter,QPixmap pixleave,QWidget*parent);
~my360button();
protected:
void enterEvent(QEvent*);
void leaveEvent(QEvent*);
void paintEvent(QPaintEvent*);
QPropertyAnimation*m_enteranimation;
QPropertyAnimation*m_leaveanimation;
QList<QPixmap> m_enterlist;
QList<QPixmap> m_leavelist;
QPixmap m_pixnormal;
int m_enterIndex;
int m_leaveIndex;
bool m_enter;
bool m_leave;
public slots:
void entervaluechange(QVariant var){m_enterIndex=var.toInt();update();}
void leavevaluechange(QVariant var){m_leaveIndex=var.toInt();update();qDebug()<<m_leaveIndex;}
};
.cpp文件
#include"my360button.h"
#include<QPainter>
#include<QDebug>
my360button::my360button(QPixmap pixnormal,QPixmap pixenter,QPixmap pixleave,QWidget*parent):QPushButton(parent)
{
setCursor(Qt::PointingHandCursor);
m_leave=false;
m_enter=true;
m_leaveIndex=0;
m_enterIndex=0;
m_pixnormal=pixnormal;
for(int i=0;i<10;i++)//进入
{
m_enterlist<<pixenter.copy(i*(pixenter.width()/10),0,pixenter.width()/10,pixenter.height());
}
for(int j=0;j<8;j++)//离开
{
m_leavelist<<pixleave.copy(j*(pixleave.width()/8),0,pixleave.width()/8,pixleave.height());
}
m_enteranimation=new QPropertyAnimation(this,"");
m_enteranimation->setStartValue(0);
m_enteranimation->setEndValue(9);
m_enteranimation->setDuration(600);
connect(m_enteranimation,SIGNAL(valueChanged(QVariant)),this,SLOT(entervaluechange(QVariant)));
m_leaveanimation=new QPropertyAnimation(this,"");
m_leaveanimation->setStartValue(0);
m_leaveanimation->setEndValue(7);
m_leaveanimation->setDuration(600);
connect(m_leaveanimation,SIGNAL(valueChanged(QVariant)),this,SLOT(leavevaluechange(QVariant)));
}
my360button::~my360button()
{
delete m_leaveanimation;
delete m_enteranimation;
}
void my360button::enterEvent(QEvent *)
{
m_enter=true;
m_leave=false;
m_enteranimation->start();
}
void my360button::leaveEvent(QEvent *)
{
m_enter=false;
m_leave=true;
m_leaveanimation->start();
}
void my360button::paintEvent(QPaintEvent *)
{
QPainter painter(this);
if(m_enter)
painter.drawPixmap(rect(),m_enterlist.at(m_enterIndex));
if(m_leave)
painter.drawPixmap(rect(),m_leavelist.at(m_leaveIndex));
}
三,demo下载:http://download.csdn.net/detail/what951006/9535965
powered by 小乌龟在大乌龟背上
更多文章:http://blog.csdn.net/what951006
相关文章推荐
- leetcode_c++: Jump Game(055)
- leetcode #64 in cpp
- 【C语言】06-基本数据类型
- c语言口令检查并限制次数输入
- leetcode_c++:Spiral Matrix(054)
- C语言的艺术:强大的宏
- ProtoBuffer的.proto文件生成c++
- C++中输入输出的十六进制八进制
- C++常见面试题—内存管理GetMemory()
- C语言的.和->的区别
- c语言学习笔记18之函数2
- 205. Isomorphic Strings
- 290. Word Pattern(技巧:记录当前位置来判断两个字符串是否符合)
- C语言学习篇-2关键字、标识符、注释
- 环形缓冲区类(C++源码
- C++学习之多态的实现
- C++变参数模板和...操作符
- leetcode #63 in cpp
- C++随笔:.NET CoreCLR之GC探索(4)
- 学习c语言遇到的一些问题(6)(随机存取)