Qchart, legend()->setGeometry 不起作用

Qchart, legend()->setGeometry does not work

本文关键字:gt setGeometry 不起作用 legend Qchart      更新时间:2023-10-16

我按照 qt 文档 https://doc-snapshots.qt.io/qt5-5.11/qtcharts-legend-example.html 将图例从图表中分离并设置分离的图例尺寸

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(( 不起作用。前两个参数有效。图例的位置是(80,50(。但是,最后两个参数不起作用。图例的宽度不是 100,图例的高度不是 180。

设置几何图形后update()应调用QLegend函数:

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

设置图例的几何图形后更新图例。m_chart->legend((->update((.

重要说明:添加线系后设置图例的几何图形.这对我有用. 当我们在添加线系列之前设置图例和图表的属性时,它将不起作用。即使在某些情况下,也会导致应用程序崩溃。