Qt/C++ 360安全卫士主界面动态按钮demo
来源:互联网 发布:竞彩缩水软件 编辑:程序博客网 时间:2024/05/19 00:14
一,先上最终效果图
由于制不来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
2 0
- Qt/C++ 360安全卫士主界面动态按钮demo
- Qt之实现360安全卫士主界面
- Qt之实现360安全卫士主界面(转)
- Qt之实现360安全卫士主界面(一)
- Qt之实现360安全卫士主界面(二)
- Qt之实现360安全卫士主界面(三)
- Qt之实现360安全卫士主界面(四)
- Qt之360安全卫士主界面(标题栏)
- Qt之实现360安全卫士主界面(一)
- Qt之实现360安全卫士主界面(二)
- Qt之实现360安全卫士主界面(三)
- Qt之实现360安全卫士主界面(四)
- Qt之实现360安全卫士主界面(一)
- Qt之实现360安全卫士主界面(二)
- Qt之实现360安全卫士主界面(三)
- Qt之实现360安全卫士主界面(四)
- Qt实现360安全卫士9.2界面
- [C/C++][界面][Qt]windows底下实现第一个Qt界面编程的demo[1]
- StrictMode 详解
- 一个登陆小案例演示Servlet的使用
- 程序猿随想
- pl/sql触发器案列
- java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/
- Qt/C++ 360安全卫士主界面动态按钮demo
- bootstrapvalidator之API学习
- leetcode #66 in cpp
- windows2008SVN安装同步web出错问题
- 修改oracle数据库的编码为utf8
- 【hdu】3231 Box Relations【拓扑排序三维】
- Creational Patterns Part 5/5: Prototype Pattern
- Python Tkinter学习笔记
- MinStack