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?
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
}