• 大小: 28KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-21
  • 语言: C/C++
  • 标签: qt  qml  c++  折线图  

资源简介

qt qml c++ 折线图

资源截图

代码片段和文件信息

#include “linechart.h“
#include 
#include 
#include 

//               1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26 27 28 29 30 31
int traffic[31]={70030060062264480072377750080076672823424522267844377823590092361884598128300 0 0 0 0 0};

LineChart::LineChart(QQuickPaintedItem *parent) :
    QQuickPaintedItem(parent)
{
    //setFlag(QGraphicsItem::ItemHasNoContents false);
    monthCount= 0;
    nameWidth= 0;
    monthNow= 0;
    topDistance=120;
}
void LineChart::paint(QPainter *painter)
{
    QDateTime current_date_time = QDateTime::currentDateTime();
    painter->setRenderHint(QPainter::Antialiasing);//平滑直线
    monthNow= current_date_time.date().month();
    dayNow= current_date_time.date().day();
    if(monthNow==2){
        nameWidth=120*28+2;
        monthCount = 28;
    }else if(monthNow==1||monthNow==3||monthNow==5||monthNow==7
             ||monthNow==8||monthNow==10||monthNow==12){
        nameWidth=120*31+2;
        monthCount = 31;
    }else{
        nameWidth=120*30+2;
        monthCount = 30;
    }
    int i=0;
    int flag=0;
    for(;i<31;i++){
        if(flag            flag=traffic[i];
        }
    }
    painter->translate(0530);//设置原点位置
    QPen penLine(Qt::white3);
    painter->setPen(penLine);
    for (int var = 0; var < dayNow; ++var) {
        if(var==0){
            painter->drawLine(0060-traffic[var]*(530-topDistance)/flag);
        }else{
            painter->drawLine((60+(var-1)*120)-traffic[var-1]*(530-topDistance)/flag120*var+60-traffic[var]*(530-topDistance)/flag);
        }
    }

    for (int var = 0; var < dayNow; ++var) {
        if(var==(dayNow-1)){
            QPen Endpoint(Qt::white10);
            painter->setPen(Endpoint);
            painter->drawEllipse((60+var*120)-5(-traffic[var]*(530-topDistance)/flag)-51010);//-5
        }else{
            //009955
//            QPen Endpoint(Qt::white3);
//            painter->setPen(Endpoint);
//            painter->drawEllipse((60+var*120)-5(-traffic[var]*(530-topDistance)/flag)-51010);//-5
//            QColor insideBrushColor0(01538525);
//            painter->setBrush(insideBrushColor0);
//            QPen penpoints0(insideBrushColor010);
//            painter->setPen(penpoints0);
            painter->drawEllipse((60+var*120)-5(-traffic[var]*(530-topDistance)/flag)-51010);//-5
        }
    }
    QPen Vertical(Qt::white1);
    painter->setPen(Vertical);
    for (int var = 0; var < dayNow; ++var) {
        painter->drawLine((60+var*120)0(60+var*120)-traffic[var]*(530-topDistance)/flag+5);
    }
    QFont notToday(“white“20);
    painter->setFont(notToday);
    for (int var = 0; var < dayNow; ++var) {
        if(var==(dayNow-1)){
            QFont isToday(“white“30);
            painter->setFont(isToday);
            QString flagstr=““;
            painter->drawText((60+var*120-60)-traffic[var]*(530-topDistan

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        3008  2014-03-26 08:50  chapter-line\chapter-line.pro.user
     文件       47231  2014-03-26 08:50  chapter-line\Makefile
     文件        2477  2014-03-26 08:44  chapter-line\main.cpp
     文件         646  2014-03-26 08:44  chapter-line\linechart.h
     文件        4366  2014-03-26 08:44  chapter-line\linechart.cpp
     文件       49414  2014-03-26 08:46  chapter-line\chapter-line
     文件         371  2014-03-26 08:49  chapter-line\chapter-line.pro
     文件        5619  2014-03-26 08:44  chapter-line\app.qml
     目录           0  2014-03-26 08:50  chapter-line\

评论

共有 条评论