gpt4 book ai didi

c++ - QCustomPlot QCPItemLine

转载 作者:搜寻专家 更新时间:2023-10-31 01:42:10 24 4
gpt4 key购买 nike

我想问一个关于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();
}

关于c++ - QCustomPlot QCPItemLine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27357095/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com