【问题标题】:limit qwtPlotZoomer selection to canvas boundaries将 qwtPlotZoomer 选择限制为画布边界
【发布时间】:2015-08-26 17:21:43
【问题描述】:

qwtPlotZoomer 的默认行为似乎是您可以选择一个超出轴刻度边界和画布大小的矩形,如 realtime 示例的此屏幕截图所示:

我想限制选择的边缘等于画布或zoomRectboundaries。有什么简单的方法可以做到这一点?

【问题讨论】:

    标签: c++ qt qwt


    【解决方案1】:

    您可以重载 move() 方法并将位置绑定到画布的 contentsRect() 那里(或者最好使用 pickArea - 通常是相同的)。

    【讨论】:

    • 这没有提供问题的答案。要批评或要求作者澄清,请在他们的帖子下方发表评论 - 您可以随时评论自己的帖子,一旦您有足够的reputation,您就可以comment on any post。
    • @Blackwood 我明白你为什么会这样想,但在这种情况下,答案是我正在寻找的有用指导,足以让我解决问题。
    【解决方案2】:

    编辑:

    根据 Uwe 的建议,我重载了 move() 函数,如下所示,这样可以防止选取器的矩形被绘制到屏幕外。

    void QZoomer::move(const QPoint& pos)
    {
        // bound the picker selection to the zoom base so you can't zoom off screen
        QPoint boundedPos = pos;
    
        if (boundedPos.x() > plot()->canvas()->contentsRect().right())  boundedPos.setX(plot()->canvas()->contentsRect().right());
        if (boundedPos.x() < plot()->canvas()->contentsRect().left())   boundedPos.setX(plot()->canvas()->contentsRect().left());
        if (boundedPos.y() < plot()->canvas()->contentsRect().top())    boundedPos.setY(plot()->canvas()->contentsRect().top());
        if (boundedPos.y() > plot()->canvas()->contentsRect().bottom()) boundedPos.setY(plot()->canvas()->contentsRect().bottom());
    
        QwtPlotPicker::move(boundedPos);
    }
    

    另一种方法是覆盖缩放功能并将rect绑定到zoomBase。这会将实际缩放限制在缩放基础上,但仍会将选取器绘制在线条之外。

    void Zoomer::zoom(const QRectF& rect)
    {
        // bound the zooming rect to the zoomBase dimensions
        QRectF boundedRect = rect & zoomBase(); 
        QwtPlotZoomer::zoom(boundedRect);
    }
    

    【讨论】:

      猜你喜欢
      • 2017-05-18
      • 2021-12-23
      • 2014-05-19
      • 1970-01-01
      • 2018-06-24
      • 2022-01-24
      • 2011-03-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多