#include "my360button.h"
#include<QPainter>
#include<QDebug>
#include<QLabel>
#include<QHBoxLayout>
#include<QFontMetrics>
mainButton::mainButton(QString strpixnormal,QString strpixenter,QString strpixleave,QWidget*parent):QPushButton(parent)
{
QPixmap pixnormal(strpixnormal);
QPixmap pixenter(strpixenter);
QPixmap pixleave(strpixleave);
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)));
}
mainButton::~mainButton()
{
delete m_leaveanimation;
delete m_enteranimation;
}
void mainButton::enterEvent(QEvent *)
{
m_enter=true;
m_leave=false;
m_enteranimation->start();
}
void mainButton::leaveEvent(QEvent *)
{
m_enter=false;
m_leave=true;
m_leaveanimation->start();
}
void mainButton::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));
}
///////////////////////////////////////////////////////////////////////////////////////////////第二组
main2Button::main2Button(QString pixnormal, QString text, QWidget *parent):QPushButton(parent)
{
this->setCursor(Qt::PointingHandCursor);
m_pix=QPixmap(pixnormal);
m_text=text;
m_enter=false;
QPixmap borpix(":/image/btnborder.png");
m_pixborder=borpix.copy(2*(borpix.width()/3),0,borpix.width()/3,borpix.height());//第二个
}
void main2Button::paintEvent(QPaintEvent *)
{
QPainter painter(this);
if(m_enter)
painter.drawPixmap(rect(),m_pixborder);
painter.drawPixmap(QRect((rect().width()-m_pix.width())/2,(rect().height()-m_pix.height())/3,m_pix.width(),m_pix.height()),m_pix);
QFont font;
QFontMetrics fontmetr(font);
int m_width= fontmetr.width(m_text);
painter.setPen(QColor(124, 124, 124));
painter.drawText(QPoint((rect().width()-m_width)/2,(rect().height()-m_pix.height())/3+m_pix.height()+20),m_text);
}
void main2Button::enterEvent(QEvent *)
{
m_enter=true;
update();
}
void main2Button::leaveEvent(QEvent *)
{
m_enter=false;
update();
}
///////////////////////////////////////////////////////////////////
main3Button::main3Button(QString pixnormal,QWidget *parent):QPushButton(parent)
{
this->setCursor(Qt::PointingHandCursor);
m_index=0;
m_enter=false;
QPixmap pix(pixnormal);
for(int i=0;i<4;i++)
m_pixlist<<pix.copy(i*(pix.width()/4),0,pix.width()/4,pix.height());
}
void main3Button::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.drawPixmap((width()-m_pixlist.at(m_index).width())/2,(height()-m_pixlist.at(m_index).height())/2
,m_pixlist.at(m_index).width()
,m_pixlist.at(m_index).height(),m_pixlist.at(m_index));//画图画到中间
}
void main3Button::enterEvent(QEvent *)
{
m_index=1;
m_enter=true;
update();
}
void main3Button::leaveEvent(QEvent *)
{
m_index=0;
m_enter=false;
update();
}
void main3Button::mousePressEvent(QMouseEvent *e)
{
if(e->button()==Qt::LeftButton)//如果是左键按下
{
m_index=2;
update();
QPushButton::mousePressEvent(e);//返回到上级
}
}
void main3Button::mouseReleaseEvent(QMouseEvent *e)
{
if(e->button()==Qt::LeftButton)//如果是左键放下
{
m_index=1;
update();
QPushButton::mouseReleaseEvent(e);//返回到上级 引出按钮clicked信号
}
}
/////////////////////////////////////////////////////////头像
headButton::headButton(QWidget*parent):QPushButton(parent)
{
setCursor(Qt::PointingHandCursor);
m_index=0;
QPixmap pixheadbor(":/image/head_bkg.png");
m_pixlist<<pixheadbor.copy(0,0,pixheadbor.width()/2,pixheadbor.height());
m_pixlist<<pixheadbor.copy(pixheadbor.width()/2,0,pixheadbor.width()/2,pixheadbor.height());
}
void headButton::paintEvent(QPaintEvent*)
{
QPainter painter(this);
painter.drawPixmap(rect(),m_pixlist.at(m_index));
QPixmap pixhead(":/image/head.png");
painter.drawPixmap((width()-pixhead.width())/2,(height()-pixhead.height())/2,pixhead.width(),pixhead.height(),pixhead);
}
void headButton::enterEvent(QEvent *)
{
m_index=1;
update();
}
void headButton::leaveEvent(QEvent *)
{
m_index=0;
update();
}
///////////////////////////////////////////////////////////////////
wordslineButton::wordslineButton(QString text,QWidget *parent):QPushButton(parent)
{
setCursor(Qt::PointingHandCursor);
m_text=text;
m_enter=false;
}
void wordslineButton::paintEvent(QPaintEvent *)
{
QPainter p(this);
QFont font;
QFontMetrics metric(font);
if(m_enter)
font.setUnderline(true);
p.setPen(Qt::white);
p.setFont(font);
p.drawText((width()-metric.width(m_text))/2,height()/2,m_text);
}
void wordslineButton::enterEvent(QEvent *)
{
m_enter=true;
update();
}
void wordslineButton::leaveEvent(QEvent *)
{
m_enter=false;
update();
}
////////////////////////////////////////////////////////////////////////////////////////////
checkButton::checkButton(QString pixcheckurl,QString pixuncheckurl, QWidget *parent):QPushButton(parent)
{
setCursor(Qt::PointingHandCursor);
setFixedSize(150,150);
m_checkindex=4;//checkbox的值
m_uncheckindex=0;//checkbox的值
m_checked=true;
m_enter=false;
m_pixcheck=QPixmap(pixcheckurl);
m_pixuncheck=QPixmap(pixuncheckurl);
QPixmap pixcheckbox(":/image/cat_checkbox.png");
for(int i=0;i<12;i++)
m_checklist<<pixcheckbox.copy(i*(pixcheckbox.width()/12),0,pixcheckbox.width(),pixcheckbox.height());
}
void checkButton::paintEvent(QPaintEvent *)
{
QPainter p(this);
QPainter p1(this);
QPixmap m_pixcheckhover(":/image/cat_hover.png");
QPixmap m_pixuncheckhover(":/image/cat_gray_hover.png");
if(m_checked)//如果选中了
{
if(m_enter)
{
p.drawPixmap(rect(),m_pixcheckhover);
p.drawPixmap(110,110,m_checklist.at(m_checkindex));
}
p1.drawPixmap(rect(),m_pixcheck);
p1.drawPixmap(110,110,m_checklist.at(m_checkindex));
}
else//如果没选中了
{
if(m_enter)
{
p.drawPixmap(rect(),m_pixuncheckhover);
p.drawPixmap(110,110,m_checklist.at(m_uncheckindex));
}
p1.drawPixmap(rect(),m_pixuncheck);
p1.drawPixmap(110,110,m_checklist.at(m_uncheckindex));
}
}
void checkButton::enterEvent(QEvent *)
{
m_checkindex=5;//选中的
m_uncheckindex=1;//黑色的
m_enter=true;
update();
}
void checkButton::mousePressEvent(QMouseEvent *e)
{
if(e->button()==Qt::LeftButton)
{
if(m_checked)
m_checked=false;
else
m_checked=true;
update();
QPushButton::mousePressEvent(e);
}
}
voi
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论






收起资源包目录





































































































共 194 条
- 1
- 2
小乌龟在大乌龟背上
- 粉丝: 932
- 资源: 28

上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助

会员权益专享
最新资源
- scrt-x86-bsafe.9.3.2.2978.exe
- scrt-x64-bsafe.9.3.2.2978.exe
- scrt-sfx-x86-bsafe.9.3.2.2978.exe
- scrt-sfx-x64-bsafe.9.3.2.2978.exe
- scrt-sfx-9.3.2-2978.macos-x64.dmg
- scrt-sfx-9.3.2-2978.macos-arm64.dmg
- scrt-9.3.2-2978.macos-x64.dmg
- scrt-9.3.2-2978.macos-arm64.dmg
- 文学系中国水墨画风格论文答辩PPT模板.pptx
- 文化气息浓厚的中国风公司介绍PPT模板.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

- 1
- 2
- 3
- 4
- 5
- 6
前往页