How write inside a pie chart
-
I tried to draw a pie chart but I want write inside..How Can I?
this is my code of the class#include "pie.h"
#include <QPainter>Pie::Pie(QWidget *parent) : QWidget(parent)
{}
void Pie::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QRectF size = QRectF(10,10,this->width()-10, this->width()-10);
painter.setBrush(Qt::gray);
painter.drawPie(size, a,b);
QPen pen(Qt::red);
//painter.setPen(pen);// painter.setRenderHints(QPainter::Antialiasing,true);
painter.pen();
painter.setBrush(Qt::gray);
painter.drawPie(size,c,d);
painter.drawText(10,10,"10");}
-
There is an example already present in the examples directory. Can you look at it.
-
@dheerendra yes but in the example they use qCharts
-
@vale88 said in How write inside a pie chart:
but I want write inside
So, your code is not doing what you want? Does it write text outside the pie?
You really should explain better what the problem is. -
@vale88 then draw it outside the pie. I'm not sure what the problem is.
-
@vale88 I guess your problem is that you do not know at which position to draw your text, so it does not cover the pie, is that correct? You need to calculate that. You know where your pie is and how big it is. You would somehow need to know how much space your text is going to occupy (bounding box). Then you can calculate the position for the text.