Trong một dự án tương tự như the QCustomPlot financial demo Tôi muốn vẽ QCPItemRect không chỉ vào khu vực biểu đồ mà còn vào khu vực bên dưới biểu đồ.QCustomPlot - hiển thị mục trên QCPAxisRect bên dưới customPlot
Có
QCPAxisRect * xRect = new QCPAxisRect(this->ui.customPlot)
...
this->ui.customPlot->plotLayout()->addElement(1, 0, xRect);
Tôi muốn thêm QCPItemRect như
QCPItemRect * xItem = new QCPItemRect(this->ui.customPlot);
xItem -> setPen (QPen (Qt::black));
xItem -> bottomRight ->setAxisRect(this->xRect);
xItem -> topLeft ->setAxisRect(this->xRect);
xItem -> bottomRight ->setCoords(x - 2.0, y - 2.0);
xItem -> topLeft ->setCoords(x + 2.0, y + 2.0);
this->ui.customPlot->addItem(xItem);
Tuy nhiên, hình chữ nhật vẫn được rút ra vào this->ui.customPlot
như trái ngược với this->xRect
. Tại sao?
Bất kỳ giúp đỡ được nhiều đánh giá cao, Daniel
CẬP NHẬT Tìm thấy một phần của câu trả lời bản thân mình, một dòng thiếu mã là
xItem -> setClipAxisRect(xRect)
Tuy chỉ làm việc với một số QCPAxisRects.
CẬP NHẬT 2 Vẫn không có. Sau đây là đoạn mã nhỏ nhất nhằm tái tạo hành vi - đủ để dán nó vào một dự án QCustomPlot trống:
// create a rectAxis, put it below the main plot
QCPAxisRect * xRect = new QCPAxisRect(this->ui.customPlot);
this->ui.customPlot->plotLayout()->addElement(1, 0, xRect);
// create a rectItem and show it on the xRect
QCPItemRect * xRectItem = new QCPItemRect(this->ui.customPlot);
xRectItem->setVisible (true);
xRectItem->setPen (QPen(Qt::transparent));
xRectItem->setBrush (QBrush(Qt::lightGray));
xRectItem->topLeft ->setType(QCPItemPosition::ptPlotCoords);
xRectItem->topLeft ->setAxisRect(xRect);
xRectItem->topLeft ->setCoords(1, 4);
xRectItem->bottomRight ->setType(QCPItemPosition::ptPlotCoords);
xRectItem->bottomRight ->setAxisRect(xRect);
xRectItem->bottomRight ->setCoords(2, 1);
xRectItem->setClipAxisRect (xRect);
xRectItem->setClipToAxisRect (false); // XXX
this->ui.customPlot->replot();[/code]
Các hành vi phụ thuộc vào việc "XXX" dòng là nhận xét ra hay không
- dòng nhận xét ra - hình chữ nhật không xuất hiện AT ALL.
- dòng bên trái trong - hình chữ nhật được vẽ vào phần chính, chẳng hạn như hiển thị here.
Bất kỳ gợi ý được nhiều đánh giá, Daniel