Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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();
                It's not about Qt. You should learn C++. Just declare the pointer in your class header file.
– Nejat
                Dec 8, 2014 at 17:43
                Ok thanks. You are right i must study c++. I did that you said and it woks. Thank you Nejat.
– Emre
                Dec 8, 2014 at 23:13
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.