Mohsin
23rd May 2021, 15:30
I have created a line graph using QChartView13641
In this graph, I want to display two squares on top of it, right beside the "Current Hit Ratio" and "Expected Hit Ratio" texts.
For that, I am using QGraphicsItem class to display squares on the QChart. code is given as you follow
<Header>
class MySqaure : public QGraphicsItem
{
public:
MySqaure();
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
};
<Cpp>
MySqaure::MySqaure()
{
}
QRectF MySqaure::boundingRect() const
{
return QRectF(0, 0, 100, 100);
}
void MySqaure::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QRectF rec = boundingRect();
QBrush brush (Qt::blue);
brush.setColor(Qt::green);
painter->fillRect(rec, brush);
painter->drawRect(rec);
}
how can I add MySquare to the Qchart view?
In this graph, I want to display two squares on top of it, right beside the "Current Hit Ratio" and "Expected Hit Ratio" texts.
For that, I am using QGraphicsItem class to display squares on the QChart. code is given as you follow
<Header>
class MySqaure : public QGraphicsItem
{
public:
MySqaure();
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
};
<Cpp>
MySqaure::MySqaure()
{
}
QRectF MySqaure::boundingRect() const
{
return QRectF(0, 0, 100, 100);
}
void MySqaure::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QRectF rec = boundingRect();
QBrush brush (Qt::blue);
brush.setColor(Qt::green);
painter->fillRect(rec, brush);
painter->drawRect(rec);
}
how can I add MySquare to the Qchart view?