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

what is the correct way to use QCPItemLine with layers? i have a pixamp which i draw on the grid with QCustomPlot and i want to draw a line above the pixmap, so far it is being shown below the pixmap.

lets say i already set a pixmap how can i be sure where the line will be shown? according to documentaions the way to draw a line is:

QCOItemLine* line = new QCOItemLine(ui->grid);
_line->start->setCoords(x_tail, y_tail);
_line->end->setCoords(x_head, y_head);
ui->widget->replot();

unlike points the line dosent related to specific graph or layer so how do i manage it?

this is how i set the pixmap:

QCPItemPixamp* _pixmap;
Qimage image;
getImageData(image);
ui->grid->addLayer("map", ui->grid->layer("main));
QPixmap pixels = QPixmap::fromImage(image.scaled(ui->grid->width(), 
ui->grid->height(), Qt::IgnoreAspectRatio, Qt::FastTransformation));
_pixmap->setVisible(true);
_pixmap->setScaled(true);
_pixmap->setPixmap(pixels);
_pixmap->topLeft->setCoords(left_x, bottom_y);
_pixmap->bottomRight->setCoords(right_x, top_y);

i want to draw a line above this pixmap

you could show how you set the pixmap in the customplot, and what do you currently get, and what do you want to get – eyllanesc Jul 31, 2018 at 6:28

You have to set a different layer to each item, and then you can use moveLayer() to move the layers.

// create layers
ui->grid->addLayer("line");
ui->grid->addLayer("pixmap");
//create line
QCPItemLine* _line = new QCPItemLine(ui->grid);
_line->start->setCoords(1, 5);
_line->end->setCoords(5, 3);
//set layer
_line->setLayer("line");
//create pixmap
QCPItemPixmap  *_pixmap = new   QCPItemPixmap(ui->grid);
QImage image;
getImageData(image);
QPixmap pixels = QPixmap::fromImage(image.scaled(ui->grid->width(),
ui->grid->height(), Qt::IgnoreAspectRatio, Qt::FastTransformation));
_pixmap->setPixmap(pixels);
_pixmap->setVisible(true);
_pixmap->setScaled(true);
_pixmap->topLeft->setCoords(1, 5);
_pixmap->bottomRight->setCoords(5, 3);
// set layer
_pixmap->setLayer("pixmap");
// move layers
ui->grid->moveLayer(_line->layer(), _pixmap->layer(), QCustomPlot::limAbove );
ui->grid->replot();
        

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.