1

我有一个包含一些曲线的 QwtPlot,我希望能够从这些曲线中获取选定的点(和曲线指针):通过单击选择一个点并通过拖动一个矩形来选择点。

我使用以下代码:

// Picker with click point machine to provide point selection
QwtPlotPicker* clickPicker = new QwtPlotPicker(this->canvas());
clickPicker->setStateMachine(new QwtPickerClickPointMachine);
clickPicker->setMousePattern(0,Qt::LeftButton,Qt::SHIFT);
connect(clickPicker, SIGNAL(appended(QPointF)),
        this, SLOT(pointSelected(QPointF)));

// Picker with drag rect machine to provide multiple points selection
QwtPlotPicker* rectPicker = new QwtPlotPicker(
            this->xBottom, this->yLeft, QwtPicker::RectRubberBand,
            QwtPicker::AlwaysOff, this->canvas());
QwtPickerDragRectMachine* test = new QwtPickerDragRectMachine();
test->setState(QwtPickerMachine::RectSelection);
rectPicker->setStateMachine(test);
connect(rectPicker, SIGNAL(selected(QRectF)),
        this, SLOT(pointsSelected(QRectF)));

但是每次单击 QwtPlot 时都会调用 pointSelected 插槽,而不仅仅是在曲线上

顺便说一句,我也尝试将一个插槽连接到信号QwtPlotPicker::selected(const QVector &pa)但它永远不会发出......

4

1 回答 1

1

我认为使用CanvasPicker示例附带的更方便,并且可以轻松扩展。

请看一下event_filterQwt附带的内容。您应该使用该类CanvasPicker(它不是 Qwt API 的一部分,但您会在示例中找到代码)。您可以使用在您的类中实例化它

    picker = new CanvasPicker(plot); // plot is a pointer to your instance of QwtPlot

您会看到事件过滤器安装在CanvasPicker.

现在看一下 CanvasPicker::eventFilter(QObject *object, QEvent *e) 在QwtPlot. 在 switch 构造 fi change 中实现您的应用程序逻辑case QEvent::MouseMove:

于 2013-05-29T11:30:21.613 回答