Results 1 to 4 of 4

Thread: Focus handling for the QwtPlot

  1. #1
    Join Date
    Sep 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Focus handling for the QwtPlot

    Hi,

    I noticed that I don't receive focus in and out events for the QwtPlot and the keyboard focus is not grabbed properly. To make it work, I have to fix two things:

    - Set setFocusPolicy(Qt::StrongFocus) on all diagrams. -> the diagram grabs the keyboard focus after a mouse click
    - Call setFocus() on the QwtPlot when e.g a mouse click happens -> fixes the focus in/out events

    I hope it helps for others.

    Csaba
    Last edited by kecsap; 18th November 2012 at 17:56.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Focus handling for the QwtPlot

    It seems you missed, that QwtPlot is a composite widget and all what needs to be done is to modify the focus policy ( QWidget::setFocusPolicy() ) for the sub widgets ( if you need something different as the default settings ).

    For the focus handling Qwt widgets are not different to any other Qt widget.

    Uwe

    PS: with QwtPlotCanvas::setFocusIndicator() you can enable/disable a focus indicator for the canvas widget.

  3. #3
    Join Date
    Sep 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Focus handling for the QwtPlot

    Quote Originally Posted by Uwe View Post
    It seems you missed, that QwtPlot is a composite widget and all what needs to be done is to modify the focus policy ( QWidget::setFocusPolicy() ) for the sub widgets ( if you need something different as the default settings ).

    For the focus handling Qwt widgets are not different to any other Qt widget.

    Uwe

    PS: with QwtPlotCanvas::setFocusIndicator() you can enable/disable a focus indicator for the canvas widget.
    Ok, I did not take into account this composite widget stuff. So 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. Also I don't know how much "Qtish" what I expect from the current situation. I do this whole thing to add gesture support for my QwtPlot widgets with my own gesture recognizers.

    PS: I use Qwt 6.0 on Ubuntu Oneiric.
    Last edited by kecsap; 18th November 2012 at 19:22.

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Focus handling for the QwtPlot

    Quote Originally Posted by kecsap View Post
    Ok, I did not take into account this composite widget stuff. So what is my expectation:
    - There is a QwtPlot widget without focus ( or other events ) 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..
    It works like this: when a widget doesn't accept the focus it is propagated to its parent. This is how Qt works - nothing special for Qwt.

    The default setting is that canvas and legend items ( depending on the mode ) accept the focus the other widgets don't. You could modify this - f.e. by setting Qt::NoFocus as focus policy for the canvas and then the plot widget will get FocusIn/Out events when you click on the canvas too, but this will break the zoomer, that handles key events on the canvas ( modifying them is probably what you really want to do ).

    Instead do "plot->setFocusProxy( plot->canvas() );" when you also want to have the focus on the canvas, when you click on the scales.

    Uwe

Similar Threads

  1. Replies: 0
    Last Post: 17th February 2012, 08:41
  2. focus events of widget children
    By daemonna in forum Newbie
    Replies: 1
    Last Post: 25th January 2011, 20:15
  3. Replies: 6
    Last Post: 14th May 2009, 12:02
  4. Focus issues / Setting multiple focus
    By ComputerPhreak in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2007, 06:09
  5. Mouse events without focus
    By latte in forum Qt Programming
    Replies: 1
    Last Post: 6th February 2007, 12:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.