-
大小: 238KB文件类型: .rar金币: 1下载: 0 次发布日期: 2021-05-09
- 语言: 其他
- 标签: qcustomplot
资源简介
qcustomplot鼠标点击后在坐标轴显示值
代码片段和文件信息
#include “axistag.h“
AxisTag::AxisTag(QCPAxis *parentAxis) : Qobject(parentAxis)
mAxis(parentAxis)
{
// The dummy tracer serves here as an invisible anchor which always sticks to the right side of
// the axis rect
mDummyTracer = new QCPItemTracer(mAxis->parentPlot());
mDummyTracer->setVisible(true);
mDummyTracer->position->setTypeX(QCPItemPosition::ptAxisRectRatio);//QCPItemPosition::ptPlotCoords
mDummyTracer->position->setTypeY(QCPItemPosition::ptPlotCoords);
mDummyTracer->position->setAxisRect(mAxis->axisRect());
mDummyTracer->position->setAxes(0 mAxis);
// mDummyTracer->position->setCoords(1 1);
// the arrow end (head) is set to move along with the dummy tracer by setting it as its parent
// anchor. Its coordinate system (setCoords) is thus pixels and this is how the needed horizontal
// offset for the tag of the second y axis is achieved. This horizontal offset gets dynamically
// updated in AxisTag::updatePosition. the arrow “start“ is simply set to have the “end“ as parent
// anchor. It is given a horizontal offset to the right which results in a 15 pixel long arrow.
mArrow = new QCPItemLine(mAxis->parentPlot());
mArrow->setlayer(“overlay“);
mArrow->setClipToAxisRect(false);
mArrow->setVisible(false);
mArrow->setHead(QCPLineEnding::esSpikeArrow);
mArrow->end->setParentAnchor(mDummyTracer->position);
mArrow->start->setParentAnchor(mArrow->end);
mArrow->start->setCoords(15 0);
// The text label is anchored at the arrow start (tail) and has its “position“ aligned at the
// left and vertically centered to the text label box.
mLabel = new QCPItemText(mAxis->parentPlot());
mLabel->setlayer(“overlay“);
mLabel->setClipToAxisRect(false);
mLabel->setPadding(QMargins(3 0 3 0));
mLabel->setBrush(QBrush(Qt::white));
mLabel->setPen(QPen(Qt::blue));
mLabel->setPositionAlignment(Qt::AlignLeft|Qt::AlignVCenter);
mLabel->position->setTypeX(QCPItemPosition::ptPlotCoords);//QCPItemPosition::ptPlotCoords
mLabel->position->setTypeY(QCPItemPosition::ptAxisRectRatio);
//mLabel->position->setParentAnchor(mDummyTracer->position);
}
AxisTag::~AxisTag()
{
if (mDummyTracer)
mDummyTracer->parentPlot()->removeItem(mDummyTracer);
if (mArrow)
mArrow->parentPlot()->removeItem(mArrow);
if (mLabel)
mLabel->parentPlot()->removeItem(mLabel);
}
void AxisTag::setPen(const QPen &pen)
{
mArrow->setPen(pen);
mLabel->setPen(pen);
}
void AxisTag::setBrush(const QBrush &brush)
{
mLabel->setBrush(brush);
}
void AxisTag::setText(const QString &text)
{
mLabel->setText(text);
}
void AxisTag::updatePosition(double value)
{
// since both the arrow and the text label are chained to the dummy tracer (via anchor
// parent-child relationships) it is sufficient to update the du
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3950 2018-04-09 14:09 axisTest\axistag.cpp
文件 841 2018-03-30 10:17 axisTest\axistag.h
文件 510 2018-04-08 10:55 axisTest\axisTest.pro
文件 18712 2018-04-12 11:50 axisTest\axisTest.pro.user
文件 183 2018-04-02 10:09 axisTest\main.cpp
文件 5139 2018-04-09 08:49 axisTest\mainwindow.cpp
文件 606 2018-04-08 16:35 axisTest\mainwindow.h
文件 654 2018-03-30 10:09 axisTest\mainwindow.ui
文件 1118717 2017-09-04 08:02 axisTest\qcustomplot.cpp
文件 266925 2017-09-04 08:02 axisTest\qcustomplot.h
文件 4207 2018-04-09 14:10 axisTest\tagaxis.cpp
文件 864 2018-04-08 17:28 axisTest\tagaxis.h
目录 0 2018-04-17 19:14 axisTest
----------- --------- ---------- ----- ----
1421308 13
- 上一篇:codesys运动控制源程序
- 下一篇:基于LabVIEW的电压温度采集
评论
共有 条评论