2012. november 18., vasárnap

Focus handling fixes for QwtPlot widget

I noticed that I don't receive focus in and out events for the QwtPlot and the keyboard focus is not grabbed properly.

What is my expectation:
- There is a QwtPlot widget without focus and if I click inside or outside the canvas area (e.g the axis area) with the left mouse button, I can grab a FocusIn event on the QwtPlot widget and the keyboard shortcuts work with the e.g QwtPlotZoomer.

Actual (out-of-box) outcome:
- Clicking on the canvas area, I don't receive FocusIn event for the QwtPlot widget (and I will never receive a FocusOut when clicking on other widgets) and the keyboard shortcuts do not work. I have to press on the canvas widget area to make the shortcuts work. I think this behavior can be confusing for the users.
- If I call the setFocusPolicy() on the QwtPlot, I receive FocusIn/FocusOut events for the QwtPlot widget only if I click outside the canvas area, but it does not work if I click on the canvas.

Workaround:
- What I must do to make everything work, call:

setFocus(); // set focus on QwtPlot widget -> makes focus in/out events work for QwtPlot
canvas()->setFocus(); // set focus on composite canvas -> keyboard shortcuts work even if the click happened outside the canvas area

... when I receive a mouse press/wheel or other related events on the QwtPlot widget.

I hope it helps for others.

Nincsenek megjegyzések: