0

我有一个 QChart,上面有许多 QLineSeries 和 QScatterSeries。我希望能够使用鼠标单击并拖动线条或框形并检测与该框相交的所有系列。

当我单击拖动时,我目前正在绘制一个 QGraphicsItem,我现在正在尝试检测该框中的哪些系列(请注意,框中可能没有实际的数据点,但可能有一段绘制的线之间插值2个数据系列点)。

我不想通过计算插值点并测试它们是否在我的选择框内来手动检测交叉点(我很确定 Qt 可以为我做到这一点),所以我尝试使用QGraphicsItem::shape()andQGraphicsItem::collidesWith()例程来检测碰撞。但是,我似乎无法获得 QLineSeries 的 QGraphicsItem 表示 - 这可能吗?

尝试使用 QPainterPath 会更好吗?在这种情况下我将如何使用它?

I also tried to use the hovered(const QPointF &, bool)signal of the data series, so I could record which series were hovered over when the selection box was dragged out, but this signal doesn't fire when the left mouse button is down for some reason. :/

4

1 回答 1

0

QLineSeries 的 QGraphicsItem 表示

QChart        ch;
QLineSeries  srs;

QList<QGraphicsItem*> bf{ch.childItems()};
ch.addSeries(&srs);
QList<QGraphicsItem*> af{ch.childItems()};

QGraphicsItem * mf;

for(auto e: af)
    if(!bf.contains(e))
        mf = e;

qDebug().operator<<(mf->isUnderMouse());
于 2019-01-11T06:43:01.547 回答