Results 1 to 2 of 2

Thread: get notified when QDockWidget gets/looses focus?

  1. #1
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default get notified when QDockWidget gets/looses focus?

    hi,

    I have a QMainWindow hosting several subclassed QDockWidgets. I would now need to detect when one of the QDockWIdgets gets or looses focus.
    There doesnt appear to be a signal for that, so i figured i have to catch the event somehow :

    Qt Code:
    1. class mydockwid : public QDockWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6.  
    7. ....
    8.  
    9. //qt event handlers
    10. virtual void focusInEvent( QFocusEvent* );
    11. };
    To copy to clipboard, switch view to plain text mode 

    But the focusInEvent() never gets called. I am also worried that QDockWidget has or will have use for focusInEvent() itself, and i break its functionality.

    How to do it properly?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: get notified when QDockWidget gets/looses focus?

    The focusInEvent() occurs only when the widget has a focus policy set. You need to call the QWidget::setFocusPolicy() for the widget. Use Qt::StrongFocus if you want both keyboard and click focus events.

    By default, QWidget has Qt::NoFocus, which means they do not receive focus events, so that's why you aren't seeing them.

    If you need your dock widget to tell other widgets that it has received (or lost) focus, use the event handlers to emit signals. If you want to be sure that you are not interfering with normal widget behavior, call the base class handler (or simply don't set the event's "accepted" parameter to true).

Similar Threads

  1. Detect when a widget looses focus?
    By thomaspu in forum Qt Programming
    Replies: 11
    Last Post: 5th April 2021, 15:58
  2. How to set focus (select) a tabbed QDockWidget?
    By serget in forum Qt Programming
    Replies: 4
    Last Post: 14th March 2012, 16:40
  3. Focus in QDockWidget disappears
    By Debilski in forum Qt Programming
    Replies: 3
    Last Post: 30th March 2011, 12:40
  4. Focus on QDockWidget
    By lynnH in forum Qt Programming
    Replies: 0
    Last Post: 20th April 2010, 11:23
  5. MDI child looses focus when app is restored
    By John_P in forum Qt Programming
    Replies: 2
    Last Post: 2nd October 2007, 10:34

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.