1. <nobr id="easjo"><address id="easjo"></address></nobr>

      <track id="easjo"><source id="easjo"></source></track>
      1. 
        

      2. <bdo id="easjo"><optgroup id="easjo"></optgroup></bdo>
      3. <track id="easjo"><source id="easjo"><em id="easjo"></em></source></track><option id="easjo"><span id="easjo"><em id="easjo"></em></span></option>
          貴州做網站公司
          貴州做網站公司~專業!靠譜!
          10年網站模板開發經驗,熟悉國內外開源網站程序,包括DEDECMS,WordPress,ZBlog,Discuz! 等網站程序,可為您提供網站建設,網站克隆,仿站,網頁設計,網站制作,網站推廣優化等服務。我們專注高端營銷型網站,企業官網,集團官網,自適應網站,手機網站,網絡營銷,網站優化,網站服務器環境搭建以及托管運維等。為客戶提供一站式網站解決方案?。?!

          qt抽獎(Qt如何編寫自定義控件實現抽獎轉盤)

          來源:互聯網轉載 時間:2024-05-08 06:13:42

          具體代碼如下

          #ifndefLOTTERYTURNTABLEWIDGET_H#defineLOTTERYTURNTABLEWIDGET_H#include<QWidget>classLotteryTurntableWidget:publicQWidget{Q_OBJECTQ_PROPERTY(introtateREADgetRotateWRITEsetRotateMEMBERpainterRotate)public:LotteryTurntableWidget(QWidget*parent=nullptr);~LotteryTurntableWidget()override;intgetRotate();voidsetRotate(introtate);protected:voidpaintEvent(QPaintEvent*event)override;voidmousePressEvent(QMouseEvent*event)override;voidmouseReleaseEvent(QMouseEvent*event)override;private:QRectcenterBtnRect;boolisPressCenterBtn{false};boolisRuning{false};intpainterRotate{0};voidonRotateFinished();QList<Qt::GlobalColor>colorList;};#endif//LOTTERYTURNTABLEWIDGET_H
          #include"lotteryturntablewidget.h"#include<QPainter>#include<QPaintEvent>#include<QPainterPath>#include<QTime>#include<QDebug>#include<QRandomGenerator>#include<QPropertyAnimation>LotteryTurntableWidget::LotteryTurntableWidget(QWidget*parent):QWidget(parent){setPalette(Qt::white);setMinimumSize(500,500);colorList<<Qt::red<<Qt::yellow<<Qt::green<<Qt::cyan<<Qt::blue<<Qt::magenta<<Qt::darkGreen<<Qt::darkCyan;}LotteryTurntableWidget::~LotteryTurntableWidget(){}intLotteryTurntableWidget::getRotate(){returnpainterRotate;}voidLotteryTurntableWidget::setRotate(introtate){painterRotate=rotate;update();}voidLotteryTurntableWidget::paintEvent(QPaintEvent*event){QPainterpainter(this);painter.setRenderHint(QPainter::Antialiasing,true);//反走樣開啟constautorect=event->rect();autoradius=std::min(rect.width(),rect.height())/2-25;painter.save();painter.translate(rect.center());//將坐標系的原點設置為(r,r)QPenpen;pen.setColor(QColor("#F0630B"));pen.setWidth(16);painter.setPen(pen);painter.drawEllipse(QPoint(0,0),radius,radius);pen.setColor(QColor("#FF4500"));pen.setWidth(8);painter.setPen(pen);radius-=8;painter.drawEllipse(QPoint(0,0),radius,radius);pen.setColor(QColor("#B71606"));pen.setWidth(40);painter.setPen(pen);radius-=24;painter.drawEllipse(QPoint(0,0),radius,radius);painter.save();if(!isRuning){painter.setPen(Qt::white);painter.setBrush(Qt::white);}for(inti=0;i<20;++i){painter.rotate(18.0);intsmallEllipse;if(i%2==0){if(isRuning){if(painterRotate%2==0){painter.setPen(Qt::red);painter.setBrush(Qt::red);}else{painter.setPen(Qt::blue);painter.setBrush(Qt::blue);}}smallEllipse=15;}else{if(isRuning){if(painterRotate%2==0){painter.setPen(Qt::blue);painter.setBrush(Qt::blue);}else{painter.setPen(Qt::red);painter.setBrush(Qt::red);}}smallEllipse=10;}painter.drawEllipse(QPoint(radius,0),smallEllipse,smallEllipse);}painter.restore();pen.setColor(QColor("#FFC228"));pen.setWidth(20);painter.setPen(pen);radius-=30;painter.drawEllipse(QPoint(0,0),radius,radius);radius-=10;autocenterRect=QRect(-radius,-radius,radius*2,radius*2);painter.setPen(Qt::transparent);painter.save();painter.rotate(18.0*painterRotate);for(inti=0;i<8;++i){QPainterPathpath;path.moveTo(0,0);path.arcTo(centerRect,45*i,45);path.closeSubpath();painter.fillPath(path,colorList[i]);}painter.restore();QPainterPathtrianglePath;//三角形QPolygonpolygon;polygon.append(QPoint(0,-radius*0.55));polygon.append(QPoint(-radius*0.25,0));polygon.append(QPoint(radius*0.25,0));trianglePath.addPolygon(polygon);painter.setBrush(QColor("#EEDAA2"));painter.drawPath(trianglePath);painter.setBrush(QColor("#FDFAEA"));radius=static_cast<int>(radius*0.3);painter.drawEllipse(QPoint(0,0),radius,radius);painter.setBrush(isPressCenterBtn?QColor("#B91A0D").lighter():QColor("#B91A0D"));//中間的按鈕radius-=2;painter.drawEllipse(QPoint(0,0),radius,radius);centerBtnRect=QRect(rect.width()/2-radius,rect.height()/2-radius,radius*2,radius*2);painter.restore();}voidLotteryTurntableWidget::mousePressEvent(QMouseEvent*event){if(isRuning){QWidget::mousePressEvent(event);return;}QRegionellipseRegion(centerBtnRect,QRegion::Ellipse);isPressCenterBtn=ellipseRegion.contains(event->pos());if(isPressCenterBtn){isRuning=true;QPropertyAnimation*animation=newQPropertyAnimation(this,"rotate");animation->setEasingCurve(QEasingCurve::InOutCubic);animation->setDuration(3000);animation->setStartValue(0);animation->setEndValue(QRandomGenerator::global()->bounded(360)+360*5);connect(animation,&QAbstractAnimation::finished,this,&LotteryTurntableWidget::onRotateFinished);animation->start(QAbstractAnimation::DeleteWhenStopped);update();}QWidget::mousePressEvent(event);}voidLotteryTurntableWidget::mouseReleaseEvent(QMouseEvent*event){if(isPressCenterBtn){isPressCenterBtn=false;update();}QWidget::mouseReleaseEvent(event);}voidLotteryTurntableWidget::onRotateFinished(){isRuning=false;}

          效果:

          讀到這里,這篇“Qt如何編寫自定義控件實現抽獎轉盤”文章已經介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領會,如果想了解更多相關內容的文章,歡迎關注本站行業資訊頻道。

          標簽:qt抽獎-

          c語言中正確的字符常量是用一對單引號將一個字符括起表示合法的字符常量。例如‘a’。數值包括整型、浮點型。整型可用十進制,八進制,十六進制。八進制前面要加0,后面...

          2022年天津專場考試原定于3月19日舉行,受疫情影響確定延期,但目前延期后的考試時間推遲。 符合報名條件的考生,須在規定時間登錄招考資訊網(www.zha...

          :喜歡聽,樂意看。指很受歡迎?!巴卣官Y料”喜聞樂見:[ xǐ wén lè jiàn ]詳細解釋1. 【解釋】:喜歡聽,樂意看。指很受歡迎。2. 【示例】:這是...

          這一天,一個偵探突然來按門鈴。小蘭一開門,一大堆玩具倒過來砸柯南。個子矮是一種罪過。這到底是怎么回事?一個大男人拿著一堆玩具在偵探的辦公室里干什么?大個子看到自己搬的玩具砸到了柯南,覺得很尷尬,于是蹲下來伸手把柯南拉了起來??履线@時候看到了這個人手上的一個細節,這個人手上有一個印記。這是柯南的習慣。他很有洞察力。然而,這個人來到毛利小五郎,一家偵探事務所尋求幫助,并希望找到毛利小五郎來解決這個案件...

          這幾天銀聯在線支付是什么意思的信息是受到大家關注度很高的,大家目前也是比較想要了解銀聯在線支付是什么意思方面的信息,那么小編今天就收集了一些關于目前銀聯在線支付是什么意思的一些信息來分享給大家,希望能夠幫助到大家吧。如何開通銀聯在線支付功能?銀聯在線支付是由中國銀聯聯合各商業銀行推出的銀行卡網上交易轉接清算平臺,開通了銀聯在線支付的銀行卡可以無需開通網上銀行即可實現網購車票、線上生活消費、境內外網...

          老漁船能經受住海水和海風幾十年甚至上百年的侵蝕,跟它們的材質有很大關系。古人用作大型海船的樹種很多,多為高密度、高硬度、油性或蠟質的優質樹種,主要有坤甸木、楸樹、柚木、鳳梨格、鐵梨木等。另外,海船體積較大,所以一般都是生長了100年以上的原木,平均直徑6米,高50多米。盡管如此,退役的古船木已經面目全非,需要經過烘干、清洗、干燥等一系列特殊工藝才能作為家具的原材料。喜歡那種船木的人,有特殊的紋理和...

          TOP
          国产初高中生视频在线观看|亚洲一区中文|久久亚洲欧美国产精品|黄色网站入口免费进人
          1. <nobr id="easjo"><address id="easjo"></address></nobr>

              <track id="easjo"><source id="easjo"></source></track>
              1. 
                

              2. <bdo id="easjo"><optgroup id="easjo"></optgroup></bdo>
              3. <track id="easjo"><source id="easjo"><em id="easjo"></em></source></track><option id="easjo"><span id="easjo"><em id="easjo"></em></span></option>