首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QCustomPlot QCPItemLine

QCustomPlot QCPItemLine
EN

Stack Overflow用户
提问于 2014-12-08 11:33:48
回答 1查看 2.4K关注 0票数 2

我想问一个关于qcustomplot的问题。如何根据滑雪板改变itemLine的位置?(如x= a)

代码语言:javascript
复制
#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 ?
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-08 12:04:09

首先,应该将指向QCPItemLine的指针保留为类成员。在此之后,horzSliderChanged插槽可能类似于:

代码语言:javascript
复制
void itemLine::horzSliderChanged(int value)
{
    item->start->setCoords(value,0);
    item->end->setCoords(value,5);
    ui->customPlot->replot();
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27357095

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档