QCPItemLine使用图层

时间:2018-07-31 06:18:10

标签: c++ qt qt5 qcustomplot

将QCPItemLine与图层一起使用的正确方法是什么? 我有一个pixamp,我用QCustomPlot绘制在网格上,我想在像素图上方绘制一条线,到目前为止,它已显示在像素图下方。

让我说我已经设置了一个像素图,如何确定行将显示在哪里? 根据文献记载,画线的方法是:

QCOItemLine* line = new QCOItemLine(ui->grid);

_line->start->setCoords(x_tail, y_tail);
_line->end->setCoords(x_head, y_head);

ui->widget->replot();

与指向与特定图形或图层相关的线剂量不同,该如何管理?

这是我设置像素图的方式:

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);

我想在此像素图上方画一条线

1 个答案:

答案 0 :(得分:0)

您必须为每个项目设置不同的图层,然后可以使用// 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(); 移动这些图层。

Booking.Date   Revenue  Month
  4/1/2018      3160    April
  4/1/2018     12656    April 
  4/1/2018      5157    April
  5/8/2018     12152      May
  5/8/2018      2824      May
  5/8/2018      4600      May
  6/30/2018     6936     June
  6/30/2018    17298     June
  6/30/2018    9625      June