Solved Triggering action by click ouside a widget
-
I have th following layout
When I click on a plot it is displayed with a thicker line to visualize that it is selected. I can then delete it with the delete button.
For each serie I add to the chart I create a connection to a slot which increases the thickness of the plot.
connect(serie, &QLineSeries::clicked, this, &AtollMain::handleClickedPlot);After a plot has been selected I would like to unselect it when I click anywhere of the Graph or outside the GraphicsView.
I tried to reimplement the mousePressEvent for the QGraphicsView for unselecting plots, but then when I click on a plot the connection previously setup doesn't work and I cannot select a plot.
How could I achieve what I'm looking for?
-
Hi
When you override the mouse press, you must still call
the base class mouse press - as else some feature might break.If you know if you have something selected, then you could use
something likevoid QGraphicsView::mousePressEvent(QMouseEvent *e) { if (somethingSelected) deselect(); // however, it must happen else QGraphicsView::mousePressEvent(e); // call base class so it can still select stuff }
-
Thank you very munch.
As a beginner with Qt I always forget that you have to forward the unhandled events.