QChartView、RubberBand 和鼠标右键行为
QChartView, RubberBand and right mouse button behaviour
我有 class,源自 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
}
我有 class,源自 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
}