繁体   English   中英

QCustomPlot QCPItemLine

[英]QCustomPlot QCPItemLine

我想问一个关于qcustomplot的问题。 如何根据Slider更改itemLine的位置? (例如x = a)

#include "itemline.h"
#include "ui_itemline.h"
#include "qcustomplot.h"

itemLine::itemLine(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::itemLine)
{
    ui->setupUi(this);

    QCPItemLine *item = new QCPItemLine(ui->customPlot);
    ui->customPlot->addItem(item);
    item->setPen(QPen(Qt::red));
    item->start->setCoords(1,0);
    item->end->setCoords(1,5);

    connect(ui->horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(horzSliderChanged(int)));
}

itemLine::~itemLine()
{
    delete ui;
}

void itemLine::horzSliderChanged(int value)
{
     // how can i change item position acording to horizontalSlider, like "x = a" line ?
}

首先,您应该将指向QCPItemLine的指针QCPItemLine为类成员。 之后, horzSliderChanged插槽可能像:

void itemLine::horzSliderChanged(int value)
{
    item->start->setCoords(value,0);
    item->end->setCoords(value,5);
    ui->customPlot->replot();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM