当前位置:   article > 正文

Qt扫盲-QXYSeries理论总结_qt qxyseries

qt qxyseries

一、概述

QXYSeries 类是折线图、曲线图、散点图的基类。这个类其实就是维护的是图线的相关信息,就比如是这个线条的颜色,每一个图点的标签,增删改查图点等功能,以及当用户对这个线条进行操作的时候,比如点击、悬浮的时候可以去绑定一些槽函数。

在这里插入图片描述

 	QLineSeries *series = new QLineSeries();
	
	//添加点
    series->append(0, 6);
    series->append(2, 4);
    series->append(3, 8);
    series->append(7, 4);
    series->append(10, 5);
    *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2);
	
	//设置线的颜色
    series->setColor(QColor(121,250,121));
    
    //设置标签
	series->setPointLabelsVisible();
    series->setPointLabelsFormat("(@xPoint, @yPoint)");
    series->setPointLabelsColor(QColor(234,121,0));
    series->setPointLabelsFont(QFont("微软雅黑", 9));
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

二、常用函数介绍

1. 维护点

熟悉基本编程的都知道,append 就是添加点、insert 插入点、remove删除点、points保存所有有序数据等等,QXYSeries 维护了图里面的数据的。我们写进去数据之后,这个自动的就绘图啦。

  • append(qreal x, qreal y)

  • append(const QPointF &point)

  • append(const QList &points)

  • at(int index) const

  • clear()

  • count() const

  • insert(int index, const QPointF &point)

  • remove(qreal x, qreal y)

  • remove(const QPointF &point)

  • remove(int index)

  • removePoints(int index, int count)

  • replace(qreal oldX, qreal oldY, qreal newX, qreal newY)

  • QList<QPointF> points() const

  • QVector<QPointF> pointsVector() const

2. 绘图相关

上图的 线 可以用 下面的函数来绘制,对于 像 setColor 就不能设置线的宽度,setPen就可以设置宽度的。可以组合使用的。

  • setBrush(const QBrush &brush)
  • setColor(const QColor &color)
  • setPen(const QPen &pen)

线的 显示隐藏就是设置 setPointsVisible(bool visible = true) 来控制的。

3. 绘制标签

绘制标签的话就是设置这些函数,但是如果

  • setPointLabelsClipping(bool enabled = true)

  • setPointLabelsColor(const QColor &color)

  • setPointLabelsFont(const QFont &font)

  • setPointLabelsFormat(const QString &format):就是控制这个显示的标签格式
    @xPoint:表示 x 坐标的占位值
    @yPoint:表示 y 坐标的占位值
    我们在其他的位置上添加这些修饰的字符串,如下图
    series->setPointLabelsFormat(“(@xPoint, @yPoint)”);

  • setPointLabelsVisible(bool visible = true):要手动设置,不然就不会显示标签的

三、信号说明

1. Point 增删相关

信号含义
pointAdded(int index)点增加信号
pointRemoved(int index)点删除信号
pointReplaced(int index)点替换信号
pointsRemoved(int index, int count)从index 的位置开始删除的点信号
pointsReplaced()点被替换

2. Point 鼠标相关

信号含义
clicked(const QPointF &point)被鼠标单点击的点位置
doubleClicked(const QPointF &point)被鼠标双击的点位置
hovered(const QPointF &point, bool state)鼠标悬停的点位置
pressed(const QPointF &point)被鼠标按压的点位置
released(const QPointF &point)释放鼠标的点位置

3. 图变化相关

信号含义
colorChanged(QColor color)图的颜色改变
penChanged(const QPen &pen)绘图的 QPen改变了
pointLabelsClippingChanged(bool clipping)图的标签改变 到 clipping
pointLabelsColorChanged(const QColor &color)图的标签颜色改变
pointLabelsFontChanged(const QFont &font)图的标签字体 改变
pointLabelsFormatChanged(const QString &format)图的标签格式改变
pointLabelsVisibilityChanged(bool visible)图的标签可视情况改变
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/781403
推荐阅读
相关标签
  

闽ICP备14008679号