我想问一个关于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
的指针保留为类成员。之后,horzSliderChanged
插槽可能像:
void itemLine::horzSliderChanged(int value)
{
item->start->setCoords(value,0);
item->end->setCoords(value,5);
ui->customPlot->replot();
}