简体   繁体   中英

QCustomPlot QCPItemLine

I want to ask a question about qcustomplot. How can i change itemLine position according to Slider? (like 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 ?
}

First you should keep the pointer to QCPItemLine as a class member. After that horzSliderChanged slot could be like :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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