qwt plot - 如何根据鼠标光标进行缩放

问题描述 投票:0回答:1

我在项目中使用了QWT。我用Qwtplotmagnifier进行缩放。我想相对于鼠标光标放大。你能帮助我吗?

qt plot qwt
1个回答
0
投票

基于这个forum post

bool ParentWidget::eventFilter(QObject *o, QEvent *e)
{
    QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(e);
    if (mouseEvent->type()==QMouseEvent::MouseButtonPress && ((mouseEvent->buttons() & Qt::LeftButton)==Qt::LeftButton)) //do zoom on a mouse click
    {
        QRectF widgetRect(mouseEvent->pos().x() - 50, mouseEvent->pos().y() - 50, 100, 100); //build a rectangle around mouse cursor position

        const QwtScaleMap xMap = plot->canvasMap(zoom->xAxis());
        const QwtScaleMap yMap = plot->canvasMap(zoom->yAxis());
        QRectF scaleRect = QRectF(
            QPointF(xMap.invTransform(widgetRect.x()), yMap.invTransform(widgetRect.y())),
            QPointF(xMap.invTransform(widgetRect.right()), yMap.invTransform(widgetRect.bottom())) ); //translate mouse rectangle to zoom rectangle

        zoom->zoom(scaleRect);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.