#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
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Qt模仿 360安全卫士 10.2版本 (194个子文件)
my360button.cpp 15KB
dnqlwidget.cpp 8KB
trayiconmenu.cpp 7KB
mainwindow.cpp 7KB
yhjswidget.cpp 5KB
upmainwindow.cpp 5KB
csxfwidget.cpp 4KB
lowmainwindow.cpp 3KB
abstmainwidget.cpp 1KB
mainwindowswidup.cpp 759B
mainwindowswidlow.cpp 707B
my360label.cpp 601B
maskmainwidget.cpp 387B
main.cpp 196B
my360button.h 5KB
mainwindow.h 2KB
trayiconmenu.h 842B
upmainwindow.h 735B
abstmainwidget.h 660B
lowmainwindow.h 552B
mainwindowswidup.h 439B
maskmainwidget.h 382B
mainwindowswidlow.h 378B
my360label.h 323B
csxfwidget.h 269B
dnqlwidget.h 267B
yhjswidget.h 231B
360logo.ico 15KB
FirstPage_Big.png 67KB
logo_normal.png 25KB
logo_speed.png 24KB
scan_button_quick.png 20KB
scan_button_custom.png 18KB
scan_button_full.png 17KB
btn_black.png 11KB
clean_soft_anim.png 10KB
clean_soft_anim_gray.png 10KB
btn_top_cdisk_scan.png 10KB
btn_top_cdisk_clean.png 9KB
btn_optimize.png 9KB
btn_carryon_opt.png 9KB
btn_fix_all.png 9KB
btn_top_clean.png 8KB
btn_top_scan (2).png 8KB
btn_top_scan.png 8KB
system_patch.png 8KB
youhua_Leave.png 8KB
btn_examine_now.png 8KB
youhua_Hover.png 8KB
btn_view_detail.png 8KB
safe_Hover.png 8KB
btn_call_ball.png 8KB
clean_Leave.png 8KB
clean_cookies_anim.png 7KB
clean_Hover.png 7KB
btn_start_scan.png 7KB
btn_rescan.png 7KB
safe_Leave.png 7KB
system_fix.png 7KB
clean_cookies_anim_gray.png 7KB
start_btn.png 5KB
scan_button_full_hover.png 5KB
clean_plugin_check.png 5KB
btn_top_cancel_scan.png 5KB
scan_button_quick_hover.png 4KB
FirstPage_2.png 4KB
btn_reexamine.png 4KB
btn_cancel_opt.png 4KB
examine_score.png 4KB
btn_fix_background.png 4KB
btn_cancel_scan.png 4KB
btn_scan_background.png 4KB
FirstPage_1.png 4KB
scan_button_custom_hover.png 4KB
clean_plugin_uncheck.png 4KB
FirstPage_4.png 4KB
clean_plugin_anim.png 4KB
clean_plugin_anim_gray.png 3KB
ico_protect_not_opened.png 3KB
win10_hover.png 3KB
win10_normal.png 3KB
win10_pressed.png 3KB
ico_protect_opened.png 3KB
clean_trace_anim.png 3KB
clean_trace_anim_gray.png 3KB
return.png 3KB
FirstPage_8.png 3KB
engStateBtnQiFa.png 3KB
engStateBtnAvira.png 3KB
engStateBtnCloud.png 3KB
engStateBtnAvira_Close.png 3KB
engStateBtnQEX.png 2KB
FirstPage_9.png 2KB
FirstPage_6.png 2KB
engStateBtnQVM.png 2KB
FirstPage_5.png 2KB
clean_soft_uncheck.png 2KB
start_check.png 2KB
cat_hover.png 2KB
start_uncheck.png 2KB
共 194 条
- 1
- 2
小乌龟在大乌龟背上
- 粉丝: 954
- 资源: 27
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页