QCustomplot 设置选中线的样式

文章目录[隐藏]

QCustomplot 设置选中线的样式前言

在我使用Qt QCustomplot 插件绘图时,我有一个需求:在折线图中,当选中某一条线时,我想要改变线的颜色和加粗线(默认是蓝色,不加粗)。
刚开始在网上查了很久的资料都没有,然后群里问也都挺忙的,并没有人回,自己看文档结果发现一个 selectionDecorator 方法。尝试了下果然可以。

QCustomplot 设置选中线的样式方法

for (int i = 0; i < m_plot - > graphCount(); ++i) {
	QCPGraph * graph = m_plot - > graph(i);
	QCPPlottableLegendItem * item = m_plot - > legend - > itemWithPlottable(graph);
	if (item - > selected() || graph - > selected()) {
		item - > setSelected(true);
		
		// 设置选中线的样式
		QPen pen;
		pen.setWidth(10);
		pen.setColor(COLOR_BLUE);
		graph - > selectionDecorator() - > setPen(pen);

		graph - > setSelection(QCPDataSelection(graph - > data() - > dataRange()));
	}
}

QCustomplot 设置选中线的样式插图
posted @ 2020-03-19 20:28  不随。  阅读(42)  评论(0编辑  收藏  举报  来源