I have created a line graph using QChartViewCapture.jpg
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>
{
public:
MySqaure();
};
class MySqaure : public QGraphicsItem
{
public:
MySqaure();
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
};
To copy to clipboard, switch view to plain text mode
<Cpp>
MySqaure::MySqaure()
{
}
QRectF MySqaure
::boundingRect() const {
return QRectF(0,
0,
100,
100);
}
{
brush.setColor(Qt::green);
painter->fillRect(rec, brush);
painter->drawRect(rec);
}
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);
}
To copy to clipboard, switch view to plain text mode
how can I add MySquare to the Qchart view?
Bookmarks