设置 X 和 Y 的间隔 QwtPlotZoneItem

Set interval for X and Y QwtPlotZoneItem

我需要使用 QwtPlotZoneItem class 在图表上绘制一个区域。我需要为 X 轴和 Y 轴设置不同的间隔,我该怎么做?

我的 QwtPlotZoneItem 的方向是 垂直,因此根据文档,如果我设置间隔,它将仅应用于 X 轴。

"For a horizontal zone the interval is related to the y axis, for a vertical zone it is related to the x axis."

我的构造函数集:

setOrientation( Qt::Vertical );
setInterval( initDate, endDate );

基本上,我需要在我的图表上创建多个代表区域的矩形,例如:

Qt 5.3.2

Qwt 6.1.0

我试图使用不正确的 class 来达到我的目的。我在 documentation:

中找到了一个 note

"For displaying an area that is bounded for x and y coordinates use QwtPlotShapeItem"

QwtPlotShapeItem class 正是我所需要的。

我基本上需要设置画笔并创建矩形,例如:

QwtPlotShapeItem *shapeItem = new QwtPlotShapeItem();

shapeItem->setBrush(QColor(255,255,255, 0));
shapeItem->setPen(QColor(Qt::transparent), 0.0, Qt::SolidLine);

// TopLeft - BottomRight
QRect myRect(QPoint(startDate, yUpperPos), QPoint(endDate, yLowerPos));
shapeItem->setRect( QRectF(myRect) );

shapeItem->attach(myQwtPlot);
myQwtPlot->replot();