gpt4 book ai didi

c++ - QChartView、RubberBand 和鼠标右键行为

转载 作者:搜寻专家 更新时间:2023-10-31 02:13:49 25 4
gpt4 key购买 nike

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

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

Qt 文档说

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.

我不想让右键缩小。我试图覆盖 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
}

但它不打印任何东西。

我怎样才能改变这种行为?

最佳答案

问题解决很简单。我刚刚混合了 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
}

关于c++ - QChartView、RubberBand 和鼠标右键行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40783089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com