1

Im trying using QCustomPlot in my gui

MainWindow.h

public:
void initArrow();

private:
QCustomPlot* grid;
QCPItemLine* arrow;

MainWindow.cpp

void MainWindow::initArrow() {
arrow = new QCPItemLine(ui->grid);
QPen pen(Qt::red);
pen.setWidth(4);

arrow->setPen(pen);
arrow->setHead(QCPLLineEnding::esLineArrow);
arrow->setHead(QCPLLineEnding::esDisc);
}

in this situation i'm playing the program, i resize the window and i see an arrow on the plot with coordinates (0,0) and (1,1). this is the code . I didnt use replot! I didnt use start! I didnt use end!

in addition, when i will understand what is the problem I'm asking what is the correct way to draw a line when i'm trying to draw above other graph.

normally if I'm using points it will be like:

QVector<double> x;
QVector<double> y;
ui->grid->graph(number)->setData(x,y);
ui->grid->graph(number)->replot();

but I cant do setData with a line and its not related to some graph so i can i Draw the line on a specefic graph??

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
asaf anter
  • 71
  • 2
  • 11
  • what is `ui->grid`? – eyllanesc Jul 29 '18 at 08:51
  • ok. in MainWindow i have QCustomPlot* grid. i want to make a function with x_start, y_start, x_end, y_end and draw an arrow accordingly – asaf anter Jul 29 '18 at 08:53
  • what is your goal? – eyllanesc Jul 29 '18 at 08:54
  • for example drawLine(1,1,4,5) will draw an arrow between those coordinates – asaf anter Jul 29 '18 at 08:57
  • If you do not explain clearly what you want and provide a decent [mcve] unfortunately I can not help you :) – eyllanesc Jul 29 '18 at 09:26
  • I edited, can you please help me :) ? – asaf anter Jul 30 '18 at 11:07
  • So far I do not understand, you could show a picture of what you currently get and another of what you want to get – eyllanesc Jul 30 '18 at 11:08
  • you really didnt understand? i cant show a picture because the computer in closed net work. i wrote the code excatly like above and i pressed play. i supposed to see an empty plot right? but there is an arrow with a tail oncoordinate (0,0) and head on (1,0) even thogh i didnt use these numbers! where do i wrong with the explanation? this is really all the code i have – asaf anter Jul 30 '18 at 11:34
  • That is the behavior of the QCPItemLine, by default it is shown and by default start is (0, 0) and end (1,1). What is your question or doubt? – eyllanesc Jul 30 '18 at 11:39
  • ok, is it shown without using the replot() function? and how can i decide the order of few lines? how can i draw green line above the red line or the oposite? – asaf anter Jul 30 '18 at 12:09
  • Yes, it is drawn without replot. What do you mean by *order*? Do you want to draw a green line instead of the red line or above? – eyllanesc Jul 30 '18 at 12:18
  • see my answer... – eyllanesc Jul 30 '18 at 12:24
  • not instead, above. like working with layers. i put on the grid pixmap, but when i add a line, the line is below the pixmap, i want it above – asaf anter Jul 30 '18 at 15:00
  • Does my answer solve the current question ?, If it did not forget to mark it as correct, that is the best way to thank. What of the layer is this question ?, I do not see it, so I invite you to create a new question and provide a [mcve] to see where the error is. The comments serve to clarify, discuss, etc. about the current question, not about other external problems. – eyllanesc Jul 30 '18 at 15:03

1 Answers1

0

QCPItemLine is drawn automatically without replot, if you want it not to be displayed you must use:

setVisible(False);

If you want it to be displayed use:

setVisible(True);
ui->grid->replot();
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • yes but before i'm using start and end, its is being plotted without it from (0,0) to (1,1). try to init the line like i did, play the program and change the window size, the line should appear from nowhere without using start and end. in addition iwant it to be on other graph, but i cant related the line to a graph – asaf anter Jul 29 '18 at 09:20