【QT】Qt Charts的实际使用中的一些小细节完善如:resetZoom、fitInView

时间:2024-04-14 08:43:56
#include <QtCharts> // 假设你已经有了一个QChartView实例 QChartView *chartView = ...; // 重置缩放到默认比例 chartView->resetTransform(); // 如果需要进一步扩展,比如添加一个按钮来控制缩放重置 QPushButton *resetZoomButton = new QPushButton("Reset Zoom"); QObject::connect(resetZoomButton, &QPushButton::clicked, [chartView]() { chartView->resetTransform(); }); // 其他可能的扩展功能,例如重新调整图表以适应窗口大小 QObject::connect(someWindowResizeEvent, [chartView]() { chartView->fitInView(chartView->chart()->plotArea(), Qt::KeepAspectRatio); });