【问题标题】:QChartView, RubberBand and right mouse button behaviourQChartView、RubberBand 和鼠标右键行为
【发布时间】:2016-11-25 17:59:42
【问题描述】:

我有类,派生自 QChartView,并且我在其中启用了橡皮筋选择

MyChartView::MyChartView(QChart* chart)
:QChartView(chart)
{
    setMouseTracking(true);
    setInteractive(true);
    setRubberBand(RectangleRubberBand);
}

Qt 文档说

如果释放鼠标左键并启用橡皮筋,则接受事件并将视图放大到橡皮筋指定的矩形。如果是鼠标右键事件,则视图被缩小。

我不想让右键缩小。我试图覆盖mouseReleaseEvent

void MyChartView::mouseReleaseEvent(QMouseEvent *e)
{
    if(e->buttons() == Qt::RightButton)
    {
        std::cout << "my overriden event" << std::endl;
        return; //event doesn't go further
    }
    QChartView::mouseReleaseEvent(e);//any other event
}

但它不打印任何东西。

如何改变这种行为?

【问题讨论】:

    标签: c++ qt qtcharts


    【解决方案1】:

    问题的解决方法很简单。我刚刚混合了button()buttons() 函数。以下代码正常工作:

    void MyChartView::mouseReleaseEvent(QMouseEvent *e)
    {
        if(e->button() == Qt::RightButton)
        {
            std::cout << "my overriden event" << std::endl;
            return; //event doesn't go further
        }
        QChartView::mouseReleaseEvent(e);//any other event
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-17
      • 2014-01-26
      • 1970-01-01
      • 2012-04-19
      • 2010-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多