這篇文章將為大家詳細(xì)講解有關(guān)Qt如何實(shí)現(xiàn)蘋果狀態(tài)切換按鈕的方法,小編覺得挺實(shí)用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
目前累計(jì)服務(wù)客戶上千余家,積累了豐富的產(chǎn)品開發(fā)及服務(wù)經(jīng)驗(yàn)。以網(wǎng)站設(shè)計(jì)水平和技術(shù)實(shí)力,樹立企業(yè)形象,為客戶提供成都網(wǎng)站制作、網(wǎng)站建設(shè)、網(wǎng)站策劃、網(wǎng)頁設(shè)計(jì)、網(wǎng)絡(luò)營銷、VI設(shè)計(jì)、網(wǎng)站改版、漏洞修補(bǔ)等服務(wù)。創(chuàng)新互聯(lián)公司始終以務(wù)實(shí)、誠信為根本,不斷創(chuàng)新和提高建站品質(zhì),通過對領(lǐng)先技術(shù)的掌握、對創(chuàng)意設(shè)計(jì)的研究、對客戶形象的視覺傳遞、對應(yīng)用系統(tǒng)的結(jié)合,為客戶提供更好的一站式互聯(lián)網(wǎng)解決方案,攜手廣大客戶,共同發(fā)展進(jìn)步。代碼如下
#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(); }