QChartView, RubberBand and right mouse button behaviour

拟墨画扇 提交于 2019-12-11 02:00:39

问题


I have class, derived from QChartView, and I have enabled rubber band selection in it

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

Qt documentation says that

If left mouse button is released and the rubber band is enabled then event is accepted and the view is zoomed into the rect specified by the rubber band. If it is a right mouse button event then the view is zoomed out.

I don't want to have right button zoom out. I tried to override 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
}

but it does not print anything.

How can I change this behaviour?


回答1:


The problem solution is very simple. I have just mixed button() and buttons() functions. The following code works properly:

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
}


来源:https://stackoverflow.com/questions/40783089/qchartview-rubberband-and-right-mouse-button-behaviour

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!