Qt如何实现苹果状态切换按钮的方法-创新互联
这篇文章将为大家详细讲解有关Qt如何实现苹果状态切换按钮的方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
目前累计服务客户上千余家,积累了丰富的产品开发及服务经验。以网站设计水平和技术实力,树立企业形象,为客户提供成都网站制作、网站建设、网站策划、网页设计、网络营销、VI设计、网站改版、漏洞修补等服务。创新互联公司始终以务实、诚信为根本,不断创新和提高建站品质,通过对领先技术的掌握、对创意设计的研究、对客户形象的视觉传递、对应用系统的结合,为客户提供更好的一站式互联网解决方案,携手广大客户,共同发展进步。代码如下
#include "button.h" #includeButton::Button(QWidget *parent) : QPushButton(parent) { status = 0; span_length = 0; rl_flag = false; release_flag =true; timeline = new QTimeLine; connect(timeline,SIGNAL(frameChanged(int)),this,SLOT(timeOut(int))); } void Button::paintEvent(QPaintEvent *e) { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); QPen pen; pen.setWidth(2); pen.setColor(QColor(219,219,219)); painter.setPen(pen); painter.setBrush(Qt::green); painter.drawRoundedRect(1,1,this->width()-2,this->height()-2,30,30); painter.setBrush(Qt::white); painter.setPen(pen); if(!rl_flag){ switch(status) { case 0:painter.drawEllipse(1,1,this->height()-3,this->height()-3);break; case 1:painter.drawRoundedRect(1,1,span_length,this->height()-2,30,30);break; case 2:painter.drawEllipse(this->width()+3-this->height(),1,this->height()-3,this->height()-3);rl_flag=true;status=0;break; } }else{ switch(status) { case 0:painter.drawEllipse(this->width()+3-this->height(),1,this->height()-3,this->height()-3);break; case 1:painter.drawRoundedRect(this->width()-1-span_length,1,span_length,this->height()-2,30,30);break; case 2:painter.drawEllipse(1,1,this->height()-3,this->height()-3);rl_flag=false;status=0;break; } } } void Button::drawSpan(QPainter painter,int s) { } void Button::mousePressEvent(QMouseEvent *e) { timeline->setDuration(400); span_length = 0; status=1; if(!rl_flag){ int r1 = this->height()-3; int r2 = (this->width()/4*3)>r1?(this->width()/4*3):r1; timeline->setFrameRange(r1,r2); }else{ int r1 = this->height()-3; int r2 = (this->width()/4*3)>r1?(this->width()/4*3):r1;//(this->width()/4*1)>r1?(this->width()/4*1):r1; timeline->setFrameRange(r1,r2); } timeline->start(); } void Button::mouseMoveEvent(QMouseEvent *e) { } void Button::mouseReleaseEvent(QMouseEvent *e) { timeline->stop(); status = 2; update(); } void Button::timeOut(int x) { status = 1; span_length = x; update(); }
本文名称:Qt如何实现苹果状态切换按钮的方法-创新互联
文章网址:http://scgulin.cn/article/djiejp.html