Qt扫盲-QXYSeries理论总结

QXYSeries是用于创建折线图、曲线图和散点图的基础类,涉及点的维护、图形绘制和标签设置。常用函数包括append添加点、setColor设置颜色、setPointLabelsVisible显示标签等。此外,还介绍了与点增删、鼠标交互及图变化相关的信号。
摘要由CSDN通过智能技术生成

一、概述

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. 维护点

熟悉基本编程的都知道,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)图的标签可视情况改变
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

太阳风暴

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值