void DiskAnalizer::paintEvent(QPaintEvent *e) { QWidget::paintEvent(e); QPainter painter; double bytesFree = getFreeSpace(drive); ui.lblBytesFree->setText(QString::number(bytesFree,'f',0)); double gbFree=(bytesFree/1048576)/1024; ui.lblGBFree->setText(QString::number(gbFree,'f',2)); double bytesUsed = getUsedSpace(drive); ui.lblBytesUsed->setText(QString::number(bytesUsed,'f',0)); double gbUsed=(bytesUsed/1048576)/1024; ui.lblGBUsed->setText(QString::number(gbUsed,'f',2)); double bytesTotal = getTotalSpace(drive); float p =((bytesFree*100)/bytesTotal); painter.begin(this); Nightcharts PieChart; PieChart.setType(Nightcharts::Pie);//{Histogramm,Pie,Dpie}; PieChart.setLegendType(Nightcharts::Vertical);//{Round,Vertical} PieChart.setCords(ui.widget->geometry().x(),ui.widget->geometry().y(),ui.widget->width(),ui.widget->height()); PieChart.addPiece("Free Space",Qt::green,p); PieChart.addPiece("Used Space",QColor(200,10,50),100); PieChart.draw(&painter); }
void PieChart::paintEvent(QPaintEvent *e) { double portion; QWidget::paintEvent(e); QPainter painter; painter.begin(this); Nightcharts PieChart; PieChart.setType(Nightcharts::Pie); PieChart.setLegendType(Nightcharts::Round); PieChart.setCords(200,200,this->width()/1.5,this->height()/1.5); double sum =0; for(int i =0; i<valsLength;i++){ sum = sum + *vals; vals++; } vals-=valsLength; for(int i =0; i<valsLength;i++){ QColor color; if(i==0){ color = QColor("Green"); }else if(i==1){ color = QColor("Blue"); }else if(i==2){ color = QColor("Orange"); }else if(i==3){ color = QColor("Red"); } else if(i==4){ color = QColor("Purple"); }else{ color = QColor("Green"); } portion = *vals / sum; portion *= 100; PieChart.addPiece(*labs,color,portion); vals++; labs++; } vals-=valsLength; labs-=valsLength; PieChart.draw(&painter); PieChart.drawLegend(&painter); }
void MainWindow::paintEvent(QPaintEvent *e) { //Setup wedge amounts float totalA=0, totalB=0, totalC=0, totalD=0, totalF=0; for(int i = 0; i < grades->count(); i++) { float percentage = grades->at(i).percentage; if(percentage >= (*gradeMinimums)[3]) totalA++; else if(percentage >= (*gradeMinimums)[2] && percentage < (*gradeMinimums)[3]) totalB++; else if(percentage >= (*gradeMinimums)[1] && percentage < (*gradeMinimums)[2]) totalC++; else if(percentage >= (*gradeMinimums)[0]) totalD++; else totalF++; } QWidget::paintEvent(e); QPainter painter; QFont font; painter.begin(this); Nightcharts PieChart; PieChart.setLegendType(Nightcharts::Vertical);//{Round,Vertical} PieChart.setCords(80,230,150,100); //PieChart.setCords(75,75,this->width()/3,this->height()/3); //Check for divide by 0 if(grades->count() == 0) { PieChart.addPiece("No Grades",Qt::green,100); } else { QString label = QString("%1 - %2").arg("A").arg(totalA); PieChart.addPiece(label,QColor(200,10,50),(totalA / grades->count())*100); label = QString("%1 - %2").arg("B").arg(totalB); PieChart.addPiece(label,Qt::green,(totalB / grades->count())*100); label = QString("%1 - %2").arg("C").arg(totalC); PieChart.addPiece(label,Qt::cyan,(totalC / grades->count())*100); label = QString("%1 - %2").arg("D").arg(totalD); PieChart.addPiece(label,Qt::yellow,(totalD / grades->count())*100); label = QString("%1 - %2").arg("F").arg(totalF); PieChart.addPiece(label,Qt::blue,totalF / (grades->count())*100); } PieChart.draw(&painter); PieChart.drawLegend(&painter); }
void Dialog::on_pushButton_clicked() { pix = QPixmap(ui->label->width(),ui->label->height()); pix.fill(colr);//(Qt::white);// QPainter painter(&pix); Nightcharts PieChart; PieChart.setType(Nightcharts::Dpie);//{Histogramm,Pie,Dpie}; PieChart.setLegendType(Nightcharts::Vertical);//{Round,Vertical,Horizontal} PieChart.setCords(120,50,ui->label->width()/2,ui->label->height()/3); PieChart.addPiece("المجموع العام السنوي",QColor(150,10,50),44); PieChart.addPiece("علي",Qt::green,27); PieChart.addPiece("كمال",Qt::cyan,4); PieChart.addPiece("عمر",Qt::yellow,7); PieChart.addPiece("ابو بكر",Qt::blue,4); PieChart.addPiece("طلحة",Qt::red,14); //PieChart.setShadows(false); PieChart.draw(&painter); PieChart.drawLegend(&painter); damj(); }
void YearStatistic::paintEvent(QPaintEvent*) { QPainter painter; painter.begin(this); Nightcharts PieChart; PieChart.setType(Nightcharts::Histogramm);//{Histogramm,Pie,DPie}; PieChart.setLegendType(Nightcharts::Vertical);//{Round,Vertical} PieChart.setCords(10, 10, 250, 280); QSqlQuery query; query.exec("SELECT au_birth_year, COUNT(*) FROM authors WHERE au_birth_year IS NOT NULL GROUP BY au_birth_year;"); int total = 0; while(query.next()) { total += query.value(1).toInt(); } if (query.first()) do { PieChart.addPiece(query.value(0).toString(), Qt::lightGray, 10000*query.value(1).toInt()/total*0.01); } while(query.next()); PieChart.draw(&painter); PieChart.drawLegend(&painter); painter.end(); }
void CPieChartWidget::paintEvent(QPaintEvent * e) { QWidget::paintEvent(e); QPainter painter(this); QFont font; Nightcharts PieChart; PieChart.setType(Nightcharts::Dpie);//{Histogramm,Pie,DPie}; PieChart.setLegendType(Nightcharts::Vertical);//{Round,Vertical} PieChart.setCords(10,10,this->width()/1.7,this->height()/1.5); std::list <PieElement>::const_iterator cit = m_list_pie_element.begin(); int count = 0; if (m_list_pie_element.empty()) { return; } int index = 0; for ( ; cit != m_list_pie_element.end (); ++cit) { QColor color = Qt::green; ++index; if (index == 1) { color = QColor(200,10,50); } if (index == 2) { color = Qt::green; } if (index == 3) { color = Qt::cyan; } if (index == 4) { color = Qt::yellow; } if (index == 5) { color = Qt::blue; } if (index == 6) { color = Qt::darkCyan; } if (index == 7) { color = Qt::color1; } if (index == 8) { color = Qt::lightGray; } if (index == 9) { color = Qt::darkMagenta; } if (index == 10) { color = Qt::darkYellow; } PieChart.addPiece(cit->name.c_str(), color, cit->data); } /*PieChart.addPiece("Item1",QColor(200,10,50),34); PieChart.addPiece("Item2",Qt::green,27); PieChart.addPiece("Item3",Qt::cyan,14); PieChart.addPiece("Item4",Qt::yellow,7); PieChart.addPiece("Item5",Qt::blue,4);*/ PieChart.draw(&painter); PieChart.drawLegend(&painter); }