QChartView Class
QChartView 是一个可显示图表的独立控件。更多内容...
| Header: | #include <QChartView> |
| Inherits: | QGraphicsView |
| Status: | Deprecated |
该类已弃用。我们强烈建议不要在新代码中使用它。
公共类型
(since 6.2) enum | RubberBand { NoRubberBand, VerticalRubberBand, HorizontalRubberBand, RectangleRubberBand, ClickThroughRubberBand } |
| flags | RubberBands |
公共函数
| QChartView(QWidget *parent = nullptr) | |
| QChartView(QChart *chart, QWidget *parent = nullptr) | |
| virtual | ~QChartView() |
| QChart * | chart() const |
| QChartView::RubberBands | rubberBand() const |
| void | setChart(QChart *chart) |
| void | setRubberBand(const QChartView::RubberBands &rubberBand) |
重新实现的受保护函数
| virtual void | mouseMoveEvent(QMouseEvent *event) override |
| virtual void | mousePressEvent(QMouseEvent *event) override |
| virtual void | mouseReleaseEvent(QMouseEvent *event) override |
| virtual void | resizeEvent(QResizeEvent *event) override |
详细说明
图表视图无需QGraphicsScene 对象即可运行。若要在现有的QGraphicsScene 中显示图表,应改用QChart 或QPolarChart 类。
另请参阅 QChart 和QPolarChart 。
成员类型文档
[since 6.2] enum QChartView::RubberBand
flags QChartView::RubberBands
此枚举描述了可应用于矩形缩放区域的各种“橡皮筋”效果。
| 常量 | 值 | 描述 |
|---|---|---|
QChartView::NoRubberBand | 0x0 | 未指定缩放区域,因此未启用缩放功能。 |
QChartView::VerticalRubberBand | 0x1 | 橡皮筋在水平方向上锁定为图表的大小,可以在垂直方向上拉动以指定缩放区域。 |
QChartView::HorizontalRubberBand | 0x2 | 橡皮筋在垂直方向上锁定为图表的大小,可以水平拖动以指定缩放区域。 |
QChartView::RectangleRubberBand | 0x3 | 橡皮筋固定在被点击的点上,可以垂直和水平方向拖动。 |
QChartView::ClickThroughRubberBand | 0x80 | 上述“橡皮筋”选项中的一项,允许将左键单击传递给图表项(前提是这些图表项支持单击)。要选择此选项,请将其与其中一种“橡皮筋”选择模式进行或运算。 |
该枚举类型在 Qt 6.2 中引入。
RubberBands 类型是QFlags<RubberBand> 的 typedef。它存储 RubberBand 值的“或”组合。
成员函数文档
[explicit] QChartView::QChartView(QWidget *parent = nullptr)
创建一个图表视图对象,其父对象为parent 。
[explicit] QChartView::QChartView(QChart *chart, QWidget *parent = nullptr)
创建一个图表视图对象,其父对象为parent ,用于显示图表chart 。该图表的所有权将传递给图表视图。
[virtual noexcept] QChartView::~QChartView()
删除图表视图对象及其关联的图表。
QChart *QChartView::chart() const
返回指向相关图表的指针。
另请参阅 setChart()。
[override virtual protected] void QChartView::mouseMoveEvent(QMouseEvent *event)
重写自:QGraphicsView::mouseMoveEvent(QMouseEvent *event)。
如果在由event 指定的按压事件中显示了橡皮筋矩形,则使用该事件数据来更新橡皮筋的几何形状。否则,将调用QGraphicsView::mouseMoveEvent()的默认实现。
[override virtual protected] void QChartView::mousePressEvent(QMouseEvent *event)
重写:QGraphicsView::mousePressEvent(QMouseEvent *event)。
如果按下了鼠标左键且“橡皮筋”功能已启用,则接受事件event ,并在屏幕上显示“橡皮筋”。这使用户能够选择缩放区域。
如果按下了其他鼠标按钮或“橡皮筋”功能被禁用,则该事件将传递给QGraphicsView::mousePressEvent()。
[override virtual protected] void QChartView::mouseReleaseEvent(QMouseEvent *event)
重写:QGraphicsView::mouseReleaseEvent(QMouseEvent *event)。
如果释放了鼠标左键且“橡皮筋”功能已启用,则接受事件event ,并将视图放大至“橡皮筋”指定的矩形范围内。如果释放鼠标右键触发了该事件,则视图将缩小。
[override virtual protected] void QChartView::resizeEvent(QResizeEvent *event)
重写:QGraphicsView::resizeEvent(QResizeEvent *event)。
使用event 指定的数据调整图表区域的大小并更新图表区域。
QChartView::RubberBands QChartView::rubberBand() const
返回图表视图当前正在使用的橡皮筋标记。
另请参阅 setRubberBand()。
void QChartView::setChart(QChart *chart)
将当前图表设置为chart 。新图表的所有权将传递给图表视图,而先前图表的所有权将被释放。
为避免内存泄漏,必须删除之前的图表。
另请参阅 chart()。
void QChartView::setRubberBand(const QChartView::RubberBands &rubberBand)
将“橡皮筋”标志设置为rubberBand 。所选标志决定了缩放的方式。
注意: 极坐标图不支持“橡皮 筋缩放”功能。
另请参阅 rubberBand()。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.