亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Qt自定義控件實(shí)現(xiàn)簡(jiǎn)易儀表盤

 更新時(shí)間:2019年12月20日 11:46:07   作者:parkchorong  
這篇文章主要為大家詳細(xì)介紹了Qt自定義控件實(shí)現(xiàn)簡(jiǎn)易儀表盤,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Qt自定義控件實(shí)現(xiàn)簡(jiǎn)易儀表盤的具體代碼,供大家參考,具體內(nèi)容如下

Qt自定義控件12:簡(jiǎn)易儀表盤(根據(jù)liudianwu大神的界面自己寫的代碼,建議去學(xué)習(xí)劉大神,會(huì)受益良多的)

先看效果圖:

思路:畫270度的圓弧,圓弧根據(jù)占比分為兩種顏色,根據(jù)占比在圓弧上畫出一個(gè)圓球作為標(biāo)志,然后就是刻度線和刻度值??潭染€是根據(jù)坐標(biāo)系旋轉(zhuǎn)畫出,刻度值是根據(jù)角度求出x,y坐標(biāo)值構(gòu)造出一個(gè)矩形畫出刻度值(不要用坐標(biāo)系旋轉(zhuǎn)畫刻度值,那樣刻度值的角度也會(huì)旋轉(zhuǎn),寫出的字不是正的,效果不好)。最后就是在中心畫value。

關(guān)鍵代碼:

void CMPassrate5::paintEvent(QPaintEvent *event){
  int width = this->width();
  int height = this->height();
  int side = qMin(width, height);

  QPainter painter(this);
  painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
  painter.translate(width / 2, height / 2);
  painter.scale(side / 200.0, side / 200.0);

  drawE(&painter);
  drawEPoint(&painter);
  drawLine(&painter);
  drawEText(&painter);
  drawValue(&painter);
}

void CMPassrate5::drawE(QPainter* painter){
  QRect rect(-radius,-radius,2*radius,2*radius);
  painter->save();
  painter->setPen(Qt::NoPen);

  QPainterPath path;
  QPainterPath subPath;
  QPainterPath outPath;
  QPainterPath outPubPath;
  outPath.arcTo(rect,-45,outRange);
  outPubPath.addEllipse(rect.adjusted(side,side,-side,-side));
  outPath -= outPubPath;
  color.setAlpha(100);
  painter->setBrush(color);
  painter->drawPath(outPath);


  path.arcTo(rect,-45+outRange,range);
  subPath.addEllipse(rect.adjusted(4,4,-4,-4));
  path -= subPath;
  color.setAlpha(180);
  painter->setBrush(color);
  painter->drawPath(path);

  painter->restore();
}

void CMPassrate5::drawEPoint(QPainter* painter){
  //圓球位置就在outRange盡頭處
  painter->save();
  color.setAlpha(180);
  painter->setPen(Qt::NoPen);
  painter->setBrush(color);

  float x = (radius-side/2)*qCos((range+135)*3.14/180);
  float y = (radius-side/2)*qSin((range+135)*3.14/180);
  qDebug()<<"x:"<<x<<" y:"<<y;
  painter->drawEllipse(QPoint(x,y),side,side);
  painter->restore();
}

void CMPassrate5::drawLine(QPainter* painter){
  painter->save();
  painter->rotate(135);
  color.setAlpha(100);
  painter->setPen(color);
  QLine line(QPoint(radius-side-lineLength,0),QPoint(radius-side,0));

  for(int i = 0;i<lineCount;i++){
    painter->drawLine(line);
    painter->rotate(270.0/lineCount);
  }
  painter->restore();
}

void CMPassrate5::drawEText(QPainter* painter){
  painter->save();
//  painter->rotate(135);
  painter->setPen(Qt::black);
  float textRange = 270.0/(textCount-1);
  float x,y;
  for(int i = 0;i<=10;i++){
    x = (radius-side-lineLength)*qCos((textRange*i+135)*3.14/180);
    y = (radius-side-lineLength)*qSin((textRange*i+135)*3.14/180);
    if(i<5){
      QRect rect(x,y-4,20,10);
      painter->drawText(rect,Qt::AlignCenter,QString::number(i*10));
    }else if(i ==5){
      QRect rect(x-7,y,20,10);
      painter->drawText(rect,Qt::AlignCenter,QString::number(i*10));
    }else{
      QRect rect(x-20,y-5,20,10);
      painter->drawText(rect,Qt::AlignCenter,QString::number(i*10));
    }

  }
  painter->restore();
}

void CMPassrate5::drawValue(QPainter* painter){
  painter->save();
  QPen pen = painter->pen();
  pen.setColor(color);
  pen.setWidth(2);
  painter->setPen(pen);
  QFont font = painter->font();
  font.setPixelSize(45);
  painter->setFont(font);

  QRect rect(-25,-25,50,50);
  painter->drawText(rect,Qt::AlignCenter,QString::number(value));
  painter->restore();
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C++實(shí)現(xiàn)LeetCode(73.矩陣賦零)

    C++實(shí)現(xiàn)LeetCode(73.矩陣賦零)

    這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(73.矩陣賦零),本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • C++的程序流程結(jié)構(gòu)你了解多少

    C++的程序流程結(jié)構(gòu)你了解多少

    這篇文章主要為大家詳細(xì)介紹了C++的程序流程結(jié)構(gòu),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-02-02
  • C++實(shí)現(xiàn)LeetCode(347.前K個(gè)高頻元素)

    C++實(shí)現(xiàn)LeetCode(347.前K個(gè)高頻元素)

    這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(347.前K個(gè)高頻元素),本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • C++繼承的定義與注意事項(xiàng)

    C++繼承的定義與注意事項(xiàng)

    這篇文章主要給大家介紹了關(guān)于C++繼承的定義與注意事項(xiàng)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-05-05
  • break的使用for循環(huán)嵌套示例

    break的使用for循環(huán)嵌套示例

    這篇文章主要介紹了break的使用for循環(huán)嵌套示例,需要的朋友可以參考下
    2014-02-02
  • C++ clock()解析如何使用時(shí)鐘計(jì)時(shí)的應(yīng)用

    C++ clock()解析如何使用時(shí)鐘計(jì)時(shí)的應(yīng)用

    本篇文章是對(duì)c++中的clock()函數(shù)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • 使用Inotify 監(jiān)控目錄與文件的方法詳解

    使用Inotify 監(jiān)控目錄與文件的方法詳解

    本篇文章是對(duì)使用Inotify 監(jiān)控目錄與文件的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • 深入理解atoi()與itoa()函數(shù)的用法

    深入理解atoi()與itoa()函數(shù)的用法

    本篇文章是對(duì)atoi()與itoa()函數(shù)的用法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • C語言 結(jié)構(gòu)體數(shù)組詳解及示例代碼

    C語言 結(jié)構(gòu)體數(shù)組詳解及示例代碼

    本文主要介紹C語言 結(jié)構(gòu)體數(shù)組,這里整理了相關(guān)資料及簡(jiǎn)單示例代碼,以便大家學(xué)習(xí)參考,有興趣的小伙伴可以看下
    2016-08-08
  • c++自帶的查找函數(shù)詳解

    c++自帶的查找函數(shù)詳解

    這篇文章主要介紹了c++自帶的查找函數(shù),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-09-09

最新評(píng)論