0
votes

I followed qt documentation https://doc-snapshots.qt.io/qt5-5.11/qtcharts-legend-example.html to detach the legend from the chart and set the detached legend dimensions

legend->detachFromChart();
m_chart->legend()->setBackgroundVisible(true);
m_chart->legend()->setBrush(QBrush(QColor(128, 128, 128, 128)));
m_chart->legend()->setPen(QPen(QColor(192, 192, 192, 192)));
m_chart->legend()->setGeometry(QRectF(80, 50, 100, 180));

m_chart->legend()->setGeometry(QRectF(80, 50, 100, 180)) does not work. the first two arguments works. The position of the legend is (80, 50). However, the last two arguments does not work. The width of the legend is not 100, and the height of the legend is not 180.

1

1 Answers

0
votes

You should call update() function of QLegend after setting geometry:

m_chart->legend()->update();