Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QFocusEvent Class Reference

The QFocusEvent class contains event parameters for widget focus events. More...

    #include <QFocusEvent>

Inherits QEvent.

- List of all members, including inherited members

### Public Types

- enum Reason { Mouse, Tab, Backtab, ActiveWindow, Popup, ..., Other }

### Public Functions

- QFocusEvent ( Type type )
- bool gotFocus () const
- bool lostFocus () const

- 2 public functions inherited from QEvent

### Static Public Members

- Reason reason ()
- void resetReason ()
- void setReason ( Reason reason )

## Detailed Description

The QFocusEvent class contains event parameters for widget focus events.

Focus events are sent to widgets when the keyboard input focus changes. Focus events occur due to mouse actions, key presses (such as Tab or Backtab), the window system, popup menus, keyboard shortcuts, or other application-specific reasons. The reason for a particular focus event is returned by reason() in the appropriate event handler.

The event handlers QWidget::focusInEvent() and QWidget::focusOutEvent() receive focus events.

Use setReason() to set the reason for all focus events, and resetReason() to reset the reason for all focus events to the previously defined reason before the last setReason() call.

See also QWidget::setFocus() and QWidget::setFocusPolicy().

## Member Type Documentation

### enum QFocusEvent::Reason

This enum specifies why the focus changed.

`QFocusEvent::Mouse` | A mouse action occurred.
`QFocusEvent::Tab` | The Tab key was pressed.
`QFocusEvent::Backtab` | A Backtab occurred. The input for this may include the Shift or Control keys; e.g. Shift+Tab.
`QFocusEvent::ActiveWindow` | The window system made this window either active or inactive.
`QFocusEvent::Popup` | The application opened/closed a popup that grabbed/released the keyboard focus.
`QFocusEvent::Shortcut` | A keyboard shortcut was input.
`QFocusEvent::Other` | Another reason, usually application-specific.

See the keyboard focus overview for more about the keyboard focus.

## Member Function Documentation

### QFocusEvent::QFocusEvent ( Type type )

Constructs a focus event object.

The type parameter must be either `QEvent::FocusIn` or `QEvent::FocusOut`.

### bool QFocusEvent::gotFocus () const

Returns true if the widget received the text input focus; otherwise returns false.

### bool QFocusEvent::lostFocus () const

Returns true if the widget lost the text input focus; otherwise returns false.

### Reason QFocusEvent::reason () `[static]`

Returns the reason for this focus event.

See also setReason().

### void QFocusEvent::resetReason () `[static]`

Resets the reason for all future focus events to the value before the last setReason() call.

See also reason() and setReason().

### void QFocusEvent::setReason ( Reason reason ) `[static]`

Sets the reason for all future focus events to reason.

See also reason() and resetReason().