【问题标题】:Qchart, legend()->setGeometry does not workQchart,legend()->setGeometry 不起作用
【发布时间】:2019-04-17 20:20:23
【问题描述】:

我按照 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。

【问题讨论】:

    标签: c++ qt qchart


    【解决方案1】:

    你应该在设置几何之后调用QLegendupdate()函数:

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

    【讨论】:

    • 我添加了m_chart->legend()->update(),但是图例的宽度和高度没有改变
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-29
      • 1970-01-01
      • 2013-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多