1 Attachment(s)
Problem with adding QGraphicsItem to QChartView
I have created a line graph using QChartViewAttachment 13641
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>
Code:
{
public:
MySqaure();
};
<Cpp>
Code:
MySqaure::MySqaure()
{
}
QRectF MySqaure
::boundingRect() const {
return QRectF(0,
0,
100,
100);
}
{
brush.setColor(Qt::green);
painter->fillRect(rec, brush);
painter->drawRect(rec);
}
how can I add MySquare to the Qchart view?
Re: Problem with adding QGraphicsItem to QChartView
QChartView inherits from QGraphicsView and therefore you can access the QGraphicsScene instance using QGraphicsView::scene(). Once you have the scene pointer, you add your own graphics items to the scene in the correct locations.