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

# QWidget Class Reference

The QWidget class is the base class of all user interface objects. More...

    #include <QWidget>

Inherits QObject and QPaintDevice.

Inherited by QDataBrowser, QDataView, Q3DateTimeEditBase, Q3DateTimeEdit, Q3DockArea, Q3Header, Q3MainWindow, QDialog, QDesktopWidget, QAbstractButton, QAbstractSlider, QAbstractSpinBox, QComboBox, QFrame, QGroupBox, QLineEdit, QMainWindow, QMenu, QMenuBar, QRubberBand, QSizeGrip, QSplashScreen, QStatusBar, QTabBar, QTabWidget, QWorkspace, and QGLWidget.

- List of all members, including inherited members
- Obsolete members
- Compatibility members

### Writable Properties

acceptDrops : bool accessibleDescription : QString accessibleName : QString autoMask : bool baseSize : QSize cursor : QCursor enabled : bool focusPolicy : Qt::FocusPolicy font : QFont geometry : QRect hidden : bool inputMethodEnabled : bool maximumHeight : int maximumSize : QSize maximumWidth : int minimumHeight : int minimumSize : QSize | minimumWidth : int mouseTracking : bool palette : QPalette pos : QPoint shown : bool size : QSize sizeIncrement : QSize sizePolicy : QSizePolicy statusTip : QString toolTip : QString updatesEnabled : bool whatsThis : QString windowIcon : QPixmap windowIconText : QString windowOpacity : double windowTitle : QString

- 1 writable property inherited from QObject

### Read-Only Properties

childrenRect : QRect childrenRegion : QRegion focus : bool focusEnabled : bool frameGeometry : QRect frameSize : QSize fullScreen : bool height : int isActiveWindow : bool isDesktop : bool isDialog : bool isModal : bool | isPopup : bool isTopLevel : bool maximized : bool microFocusHint : QRect minimized : bool minimumSizeHint : QSize rect : QRect sizeHint : QSize visible : bool width : int x : int y : int

### Public Functions

- QWidget ( QWidget * parent = 0, Qt::WFlags f = 0 )
- ~QWidget ()
- QList<QAction *> actions () const
- void addAction ( QAction * action )
- void addActions ( QList<QAction *> actions )
- void adjustSize ()
- QPalette::ColorRole backgroundRole () const
- QWidget * childAt ( int x, int y ) const
- QWidget * childAt ( const QPoint & p ) const
- void clearFocus ()
- void clearMask ()
- QRegion clipRegion () const
- QSize contentsMarginSize () const
- QRect contentsRect () const
- void ensurePolished () const
- QWidget * focusProxy () const
- QWidget * focusWidget () const
- QFontInfo fontInfo () const
- QFontMetrics fontMetrics () const
- QPalette::ColorRole foregroundRole () const
- virtual HDC getDC () const
- void grabKeyboard ()
- void grabMouse ()
- void grabMouse ( const QCursor & cursor )
- int grabShortcut ( const QKeySequence & key, Qt::ShortcutContext context = Qt::ShortcutOnActiveWindow )
- virtual int heightForWidth ( int w ) const
- void insertAction ( QAction * before, QAction * action )
- void insertActions ( QAction * before, QList<QAction *> actions )
- bool isEnabledTo ( QWidget * ancestor ) const
- bool isVisibleTo ( QWidget * ancestor ) const
- QLayout * layout () const
- QPoint mapFrom ( QWidget * parent, const QPoint & pos ) const
- QPoint mapFromGlobal ( const QPoint & pos ) const
- QPoint mapFromParent ( const QPoint & pos ) const
- QPoint mapTo ( QWidget * parent, const QPoint & pos ) const
- QPoint mapToGlobal ( const QPoint & pos ) const
- QPoint mapToParent ( const QPoint & pos ) const
- QRegion mask () const
- QWidget * nextInFocusChain () const
- virtual QPaintEngine * paintEngine () const
- QWidget * parentWidget () const
- virtual void releaseDC ( HDC hdc ) const
- void releaseKeyboard ()
- void releaseMouse ()
- void releaseShortcut ( int id )
- void removeAction ( QAction * action )
- void repaint ( int x, int y, int w, int h )
- void repaint ( const QRect & r )
- void repaint ( const QRegion & rgn )
- void scroll ( int dx, int dy )
- void scroll ( int dx, int dy, const QRect & r )
- void setActiveWindow ()
- void setAttribute ( Qt::WidgetAttribute attribute, bool on = true )
- void setBackgroundRole ( QPalette::ColorRole role )
- void setContentsMargins ( int left, int top, int right, int bottom )
- void setFixedHeight ( int h )
- void setFixedSize ( const QSize & s )
- void setFixedSize ( int w, int h )
- void setFixedWidth ( int w )
- void setFocusProxy ( QWidget * w )
- void setForegroundRole ( QPalette::ColorRole role )
- void setMask ( const QBitmap & bitmap )
- void setMask ( const QRegion & region )
- void setParent ( QWidget * parent )
- void setParent ( QWidget * parent, Qt::WFlags f )
- void setShortcutEnabled ( int id, bool enable = true )
- void setStyle ( QStyle * style )
- QStyle * setStyle ( const QString & style )
- void setWindowRole ( const QString & role )
- void setWindowState ( uint windowState )
- void stackUnder ( QWidget * w )
- QStyle & style () const
- bool testAttribute ( Qt::WidgetAttribute attribute ) const
- Qt::WFlags testWFlags ( Qt::WFlags f ) const
- QWidget * topLevelWidget () const
- bool underMouse () const
- void update ( int x, int y, int w, int h )
- void update ( const QRect & r )
- void update ( const QRegion & rgn )
- void updateGeometry ()
- WId winId () const
- QString windowRole () const
- uint windowState () const
- Qt::HANDLE xftDrawHandle () const
- Qt::HANDLE xftPictureHandle () const

- 24 public functions inherited from QObject
- 2 public functions inherited from QPaintDevice

### Public Slots

- bool close ()
- virtual void hide ()
- void lower ()
- void raise ()
- void repaint ()
- void setDisabled ( bool disable )
- void setEnabled ( bool )
- void setFocus ()
- void setHidden ( bool hide )
- void setShown ( bool show )
- virtual void show ()
- void showFullScreen ()
- void showMaximized ()
- void showMinimized ()
- void showNormal ()
- void update ()

- 1 public slot inherited from QObject

### Signals

- 1 signal inherited from QObject

### Static Public Members

- QWidget * find ( WId id )
- QWidget * keyboardGrabber ()
- QWidget * mouseGrabber ()
- void setTabOrder ( QWidget * first, QWidget * second )

- 4 static public members inherited from QObject

### Protected Functions

- virtual void actionEvent ( QActionEvent * event )
- virtual void changeEvent ( QEvent * e )
- void clearWFlags ( Qt::WFlags f )
- virtual void closeEvent ( QCloseEvent * e )
- virtual void contextMenuEvent ( QContextMenuEvent * e )
- void create ( WId window = 0, bool initializeWindow = true, bool destroyOldWindow = true )
- void destroy ( bool destroyWindow = true, bool destroySubWindows = true )
- virtual void dragEnterEvent ( QDragEnterEvent * event )
- virtual void dragLeaveEvent ( QDragLeaveEvent * event )
- virtual void dragMoveEvent ( QDragMoveEvent * event )
- virtual void dropEvent ( QDropEvent * event )
- virtual void enterEvent ( QEvent * event )
- virtual bool event ( QEvent * e )
- virtual void focusInEvent ( QFocusEvent * event )
- virtual bool focusNextPrevChild ( bool next )
- virtual void focusOutEvent ( QFocusEvent * event )
- Qt::WFlags getWFlags () const
- virtual void hideEvent ( QHideEvent * event )
- virtual void imComposeEvent ( QIMEvent * e )
- virtual void imEndEvent ( QIMEvent * e )
- virtual void imStartEvent ( QIMEvent * e )
- virtual void keyPressEvent ( QKeyEvent * e )
- virtual void keyReleaseEvent ( QKeyEvent * e )
- virtual void leaveEvent ( QEvent * event )
- virtual bool macEvent ( EventHandlerCallRef caller, EventRef event )
- virtual int metric ( int m ) const
- virtual void mouseDoubleClickEvent ( QMouseEvent * e )
- virtual void mouseMoveEvent ( QMouseEvent * e )
- virtual void mousePressEvent ( QMouseEvent * e )
- virtual void mouseReleaseEvent ( QMouseEvent * e )
- virtual void moveEvent ( QMoveEvent * event )
- virtual void paintEvent ( QPaintEvent * event )
- virtual void polishEvent ( QEvent * event )
- virtual bool qwsEvent ( QWSEvent * event )
- void resetInputContext ()
- virtual void resizeEvent ( QResizeEvent * event )
- void setMicroFocusHint ( int x, int y, int width, int height, bool text = true, QFont * f = 0 )
- void setWFlags ( Qt::WFlags f )
- virtual void showEvent ( QShowEvent * event )
- virtual void tabletEvent ( QTabletEvent * e )
- virtual void updateMask ()
- virtual void wheelEvent ( QWheelEvent * e )
- virtual bool winEvent ( MSG * event )
- virtual bool x11Event ( XEvent * event )

- 9 protected functions inherited from QObject

## Detailed Description

The QWidget class is the base class of all user interface objects.

The widget is the atom of the user interface: it receives mouse, keyboard and other events from the window system, and paints a representation of itself on the screen. Every widget is rectangular, and they are sorted in a Z-order. A widget is clipped by its parent and by the widgets in front of it.

A widget that isn't embedded in a parent widget is called a top-level widget. Usually, top-level widgets are windows with a frame and a title bar (although it is also possible to create top-level widgets without such decoration if suitable widget flags are used). In Qt, QMainWindow and the various subclasses of QDialog are the most common top-level windows.

A widget without a parent widget is always a top-level widget.

Non-top-level widgets are child widgets. These are child windows in their parent widgets. You cannot usually distinguish a child widget from its parent visually. Most other widgets in Qt are useful only as child widgets. (It is possible to make, say, a button into a top-level widget, but most people prefer to put their buttons inside other widgets, e.g. QDialog.)

If you want to use a QWidget to hold child widgets you will probably want to add a layout to the parent QWidget. (See Layouts.)

QWidget has many member functions, but some of them have little direct functionality: for example, QWidget has a font property, but never uses this itself. There are many subclasses which provide real functionality, such as QPushButton, QListBox and QTabDialog, etc.

### Groups of functions:

Context | Functions
--- | ---
Window functions | show(), hide(), raise(), lower(), close().
Top level windows | windowModified(), setWindowModified(), windowTitle(), setWindowTitle(), windowIcon(), setWindowIcon(), windowIconText(), setWindowIconText(), isActiveWindow(), setActiveWindow(), showMinimized(). showMaximized(), showFullScreen(), showNormal().
Window contents | update(), repaint(), erase(), scroll(), updateMask().
Geometry | pos(), size(), rect(), x(), y(), width(), height(), sizePolicy(), setSizePolicy(), sizeHint(), updateGeometry(), layout(), move(), resize(), setGeometry(), frameGeometry(), geometry(), childrenRect(), adjustSize(), mapFromGlobal(), mapFromParent() mapToGlobal(), mapToParent(), maximumSize(), minimumSize(), sizeIncrement(), setMaximumSize(), setMinimumSize(), setSizeIncrement(), setBaseSize(), setFixedSize()
Mode | isVisible(), isVisibleTo(), isMinimized(), isDesktop(), isEnabled(), isEnabledTo(), isModal(), isPopup(), isTopLevel(), setEnabled(), hasMouseTracking(), setMouseTracking(), isUpdatesEnabled(), setUpdatesEnabled(), clipRegion().
Look and feel | style(), setStyle(), cursor(), setCursor() font(), setFont(), palette(), setPalette(), backgroundRole(), setBackgroundRole(), fontMetrics(), fontInfo().
Keyboard focus<br>functions | isFocusEnabled(), setFocusPolicy(), focusPolicy(), hasFocus(), setFocus(), clearFocus(), setTabOrder(), setFocusProxy().
Mouse and<br>keyboard grabbing | grabMouse(), releaseMouse(), grabKeyboard(), releaseKeyboard(), mouseGrabber(), keyboardGrabber().
Event handlers | event(), mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), keyPressEvent(), keyReleaseEvent(), focusInEvent(), focusOutEvent(), wheelEvent(), enterEvent(), leaveEvent(), paintEvent(), moveEvent(), resizeEvent(), closeEvent(), dragEnterEvent(), dragMoveEvent(), dragLeaveEvent(), dropEvent(), childEvent(), showEvent(), hideEvent(), customEvent(). changeEvent(),
System functions | parentWidget(), topLevelWidget(), setParent(), winId(), find(), metric().
What's this help | setWhatsThis()
Internal kernel<br>functions | focusNextPrevChild(), wmapper(), clearWFlags(), getWFlags(), setWFlags(), testWFlags().

Every widget's constructor accepts one or two standard arguments:

1. `QWidget *parent = 0` is the parent of the new widget. If it is 0 (the default), the new widget will be a top-level window. If not, it will be a child of parent, and be constrained by parent's geometry (unless you specify `Qt::WType_TopLevel` as widget flag).
2. `Qt::WFlags f = 0` (where available) sets the widget flags; the default is suitable for almost all widgets, but to get, for example, a top-level widget without a window system frame, you must use special flags.

The tictac/tictac.cpp example program is good example of a simple widget. It contains a few event handlers (as all widgets must), a few custom routines that are specific to it (as all useful widgets do), and has a few children and connections. Everything it does is done in response to an event: this is by far the most common way to design GUI applications.

You will need to supply the content for your widgets yourself, but here is a brief run-down of the events, starting with the most common ones:

- paintEvent() - called whenever the widget needs to be repainted. Every widget which displays output must implement it. Painting using a QPainter can only take place in a paintEvent() or a function called by a paintEvent().
- resizeEvent() - called when the widget has been resized.
- mousePressEvent() - called when a mouse button is pressed. There are six mouse-related events, but the mouse press and mouse release events are by far the most important. A widget receives mouse press events when the mouse is inside it, or when it has grabbed the mouse using grabMouse().
- mouseReleaseEvent() - called when a mouse button is released. A widget receives mouse release events when it has received the corresponding mouse press event. This means that if the user presses the mouse inside your widget, then drags the mouse to somewhere else, then releases, your widget receives the release event. There is one exception: if a popup menu appears while the mouse button is held down, this popup immediately steals the mouse events.
- mouseDoubleClickEvent() - not quite as obvious as it might seem. If the user double-clicks, the widget receives a mouse press event (perhaps a mouse move event or two if they don't hold the mouse quite steady), a mouse release event and finally this event. It is not possible to distinguish a click from a double click until you've seen whether the second click arrives. (This is one reason why most GUI books recommend that double clicks be an extension of single clicks, rather than trigger a different action.)

If your widget only contains child widgets, you probably do not need to implement any event handlers. If you want to detect a mouse click in a child widget call the child's underMouse() function inside the parent widget's mousePressEvent().

Widgets that accept keyboard input need to reimplement a few more event handlers:

- keyPressEvent() - called whenever a key is pressed, and again when a key has been held down long enough for it to auto-repeat. Note that the Tab and Shift+Tab keys are only passed to the widget if they are not used by the focus-change mechanisms. To force those keys to be processed by your widget, you must reimplement QWidget::event().
- focusInEvent() - called when the widget gains keyboard focus (assuming you have called setFocusPolicy()). Well written widgets indicate that they own the keyboard focus in a clear but discreet way.
- focusOutEvent() - called when the widget loses keyboard focus.

Some widgets will also need to reimplement some of the less common event handlers:

- mouseMoveEvent() - called whenever the mouse moves while a button is held down. This is useful for, for example, dragging. If you call setMouseTracking(true), you get mouse move events even when no buttons are held down. (See also the drag and drop information.)
- keyReleaseEvent() - called whenever a key is released, and also while it is held down if the key is auto-repeating. In that case the widget receives a key release event and immediately a key press event for every repeat. Note that the Tab and Shift+Tab keys are only passed to the widget if they are not used by the focus-change mechanisms. To force those keys to be processed by your widget, you must reimplement QWidget::event().
- wheelEvent() -- called whenever the user turns the mouse wheel while the widget has the focus.
- enterEvent() - called when the mouse enters the widget's screen space. (This excludes screen space owned by any children of the widget.)
- leaveEvent() - called when the mouse leaves the widget's screen space.
- moveEvent() - called when the widget has been moved relative to its parent.
- closeEvent() - called when the user closes the widget (or when close() is called).

There are also some rather obscure events. They are listed in `qevent.h` and you need to reimplement event() to handle them. The default implementation of event() handles Tab and Shift+Tab (to move the keyboard focus), and passes on most other events to one of the more specialized handlers above.

When implementing a widget, there are a few more things to consider.

- In the constructor, be sure to set up your member variables early on, before there's any chance that you might receive an event.
- It is almost always useful to reimplement sizeHint() and to set the correct size policy with setSizePolicy(), so users of your class can set up layout management more easily. A size policy lets you supply good defaults for the layout management handling, so that other widgets can contain and manage yours easily. sizeHint() indicates a "good" size for the widget.
- If your widget is a top-level window, setWindowTitle() and setWindowIcon() set the title bar and icon respectively.

From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent() to avoid flicker.

See also QEvent, QPainter, QGridLayout, and QBoxLayout.

## Property Documentation

### acceptDrops : bool

This property holds whether drop events are enabled for this widget.

Setting this property to true announces to the system that this widget may be able to accept drop events.

If the widget is the desktop (QWidget::isDesktop()), this may fail if another application is using the desktop; you can call acceptDrops() to test if this occurs.

Warning: Do not modify this property in a Drag&Drop event handler.

Access functions:

- bool acceptDrops () const
- void setAcceptDrops ( bool on )

### accessibleDescription : QString

This property holds the widget's description as seen by assistive technologies.

Access functions:

- QString accessibleDescription () const
- void setAccessibleDescription ( const QString & description )

See also QAccessibleInterface::text.

### accessibleName : QString

This property holds the widget's name as seen by assistive technologies.

Access functions:

- QString accessibleName () const
- void setAccessibleName ( const QString & name )

See also QAccessibleInterface::text.

### autoMask : bool

This property holds whether the auto mask feature is enabled for the widget.

Transparent widgets use a mask to define their visible region. QWidget has some built-in support to make the task of recalculating the mask easier. When setting auto mask to true, updateMask() will be called whenever the widget is resized or changes its focus state. Note that you must reimplement updateMask() (which should include a call to setMask()) or nothing will happen.

Note: when you re-implement resizeEvent(), focusInEvent() or focusOutEvent() in your custom widgets and still want to ensure that the auto mask calculation works, you should add:

        if (autoMask())
            updateMask();

at the end of your event handlers. This is true for all member functions that change the appearance of the widget in a way that requires a recalculation of the mask.

While being a technically appealing concept, masks have a big drawback: when using complex masks that cannot be expressed easily with relatively simple regions, they can be very slow on some window systems. The classic example is a transparent label. The complex shape of its contents makes it necessary to represent its mask by a bitmap, which consumes both memory and time. If all you want is to blend the background of several neighboring widgets together seamlessly, you will probably want to use setBackgroundOrigin() rather than a mask.

Access functions:

- bool autoMask () const
- void setAutoMask ( bool )

See also autoMask(), updateMask(), setMask(), and clearMask().

### baseSize : QSize

This property holds the base size of the widget.

The base size is used to calculate a proper widget size if the widget defines sizeIncrement().

Access functions:

- QSize baseSize () const
- void setBaseSize ( const QSize & )
- void setBaseSize ( int basew, int baseh )

See also setSizeIncrement().

### childrenRect : QRect

This property holds the bounding rectangle of the widget's children.

Hidden children are excluded.

Access functions:

- QRect childrenRect () const

See also childrenRegion() and geometry().

### childrenRegion : QRegion

This property holds the combined region occupied by the widget's children.

Hidden children are excluded.

Access functions:

- QRegion childrenRegion () const

See also childrenRect() and geometry().

### cursor : QCursor

This property holds the cursor shape for this widget.

The mouse cursor will assume this shape when it's over this widget. See the list of predefined cursor objects for a range of useful shapes.

An editor widget might use an I-beam cursor:

        setCursor(Qt::IbeamCursor);

If no cursor has been set, or after a call to unsetCursor(), the parent's cursor is used. The function unsetCursor() has no effect on top-level widgets.

Access functions:

- QCursor cursor () const
- void setCursor ( const QCursor & )
- void unsetCursor ()

See also QApplication::setOverrideCursor().

### enabled : bool

This property holds whether the widget is enabled.

An enabled widget receives keyboard and mouse events; a disabled widget does not. In fact, an enabled widget only receives keyboard events when it is in focus.

Some widgets display themselves differently when they are disabled. For example a button might draw its label grayed out. If your widget needs to know when it becomes enabled or disabled, you can use the changeEvent() with type QEvent::EnabledChange.

Disabling a widget implicitly disables all its children. Enabling respectively enables all child widgets unless they have been explicitly disabled.

Access functions:

- bool isEnabled () const
- void setEnabled ( bool )

See also isEnabled(), isEnabledTo(), QKeyEvent, QMouseEvent, and changeEvent().

### focus : bool

This property holds whether this widget (or its focus proxy) has the keyboard input focus.

Effectively equivalent to `qApp->focusWidget() == this`.

Access functions:

- bool hasFocus () const

See also setFocus(), clearFocus(), setFocusPolicy(), and QApplication::focusWidget().

### focusEnabled : bool

This property holds whether the widget accepts keyboard focus.

Keyboard focus is initially disabled (i.e. focusPolicy() == `QWidget::NoFocus`).

You must enable keyboard focus for a widget if it processes keyboard events. This is normally done from the widget's constructor. For instance, the QLineEdit constructor calls setFocusPolicy(QWidget::StrongFocus).

Access functions:

- bool isFocusEnabled () const

See also setFocusPolicy(), focusInEvent(), focusOutEvent(), keyPressEvent(), keyReleaseEvent(), and isEnabled().

### focusPolicy : Qt::FocusPolicy

This property holds the way the widget accepts keyboard focus.

The policy is `QWidget::TabFocus` if the widget accepts keyboard focus by tabbing, `QWidget::ClickFocus` if the widget accepts focus by clicking, `QWidget::StrongFocus` if it accepts both, and `QWidget::NoFocus` (the default) if it does not accept focus at all.

You must enable keyboard focus for a widget if it processes keyboard events. This is normally done from the widget's constructor. For instance, the QLineEdit constructor calls setFocusPolicy(QWidget::StrongFocus).

Access functions:

- Qt::FocusPolicy focusPolicy () const
- void setFocusPolicy ( Qt::FocusPolicy )

See also focusEnabled, focusInEvent(), focusOutEvent(), keyPressEvent(), keyReleaseEvent(), and enabled.

### font : QFont

This property holds the font currently set for the widget.

The fontInfo() function reports the actual font that is being used by the widget.

As long as no special font has been set, or after setFont(QFont()) is called, this is either a special font for the widget class, the parent's font or (if this widget is a top level widget), the default application font.

This code fragment sets a 12 point helvetica bold font:

        QFont f("Helvetica", 12, QFont::Bold);
        setFont(f);

In addition to setting the font, setFont() informs all children about the change.

Access functions:

- const QFont & font () const
- void setFont ( const QFont & )
- void setFont ( const QFont & f, bool b )

See also fontInfo() and fontMetrics().

### frameGeometry : QRect

This property holds geometry of the widget relative to its parent including any window frame.

See the Window Geometry documentation for an overview of geometry issues with top-level widgets.

Access functions:

- QRect frameGeometry () const

See also geometry(), x(), y(), and pos().

### frameSize : QSize

This property holds the size of the widget including any window frame.

Access functions:

- QSize frameSize () const

### fullScreen : bool

This property holds whether the widget is full screen.

Access functions:

- bool isFullScreen () const

See also windowState(), minimized, and maximized.

### geometry : QRect

This property holds the geometry of the widget relative to its parent and excluding the window frame.

When changing the geometry, the widget, if visible, receives a move event (moveEvent()) and/or a resize event (resizeEvent()) immediately. If the widget is not currently visible, it is guaranteed to receive appropriate events before it is shown.

The size component is adjusted if it lies outside the range defined by minimumSize() and maximumSize().

Warning: Calling setGeometry() inside resizeEvent() or moveEvent() can lead to infinite recursion.

See the Window Geometry documentation for an overview of top-level widget geometry.

Access functions:

- const QRect & geometry () const
- void setGeometry ( int x, int y, int w, int h )
- void setGeometry ( const QRect & )

See also frameGeometry(), rect(), move(), resize(), moveEvent(), resizeEvent(), minimumSize(), and maximumSize().

### height : int

This property holds the height of the widget excluding any window frame.

See the Window Geometry documentation for an overview of top-level widget geometry.

Access functions:

- int height () const

See also geometry, width, and size.

### hidden : bool

This property holds whether the widget is explicitly hidden.

If false, the widget is visible or would become visible if all its ancestors became visible.

Access functions:

- bool isHidden () const
- void setHidden ( bool hide )

See also hide(), show(), isVisible(), isVisibleTo(), and shown.

### inputMethodEnabled : bool

This property holds enables or disables the use of input methods for this widget.

Most Widgets (as eg. buttons) that do not handle text input should have the input method disabled if they have focus. This is the default.

If a widget handles text input it should set this property to true.

Access functions:

- bool isInputMethodEnabled () const
- void setInputMethodEnabled ( bool b )

### isActiveWindow : bool

This property holds whether this widget is the active window.

The active window is the window (or child of the window) that has keyboard focus.

When popup windows are visible, this property is true for both the active window and for the popup.

Access functions:

- bool isActiveWindow () const

See also setActiveWindow() and QApplication::activeWindow().

### isDesktop : bool

This property holds whether the widget is a desktop widget, i.e. represents the desktop.

A desktop widget is also a top-level widget.

Access functions:

- bool isDesktop () const

See also isTopLevel() and QApplication::desktop().

### isDialog : bool

This property holds whether the widget is a dialog widget.

A dialog widget is a secondary top-level widget, i.e. a top-level widget with a parent.

Access functions:

- bool isDialog () const

See also isTopLevel() and QDialog.

### isModal : bool

This property holds whether the widget is a modal widget.

This property only makes sense for top-level widgets. A modal widget prevents widgets in all other top-level widgets from getting any input.

Access functions:

- bool isModal () const

See also isTopLevel(), isDialog(), and QDialog.

### isPopup : bool

This property holds whether the widget is a popup widget.

A popup widget is created by specifying the widget flag `Qt::WType_Popup` to the widget constructor. A popup widget is also a top-level widget.

Access functions:

- bool isPopup () const

See also isTopLevel().

### isTopLevel : bool

This property holds whether the widget is a top-level widget.

A top-level widget is a widget which usually has a frame and a title. Popup and desktop widgets are also top-level widgets.

A top-level widget can have a parent widget. It will then be grouped with its parent and deleted when the parent is deleted, minimized when the parent is minimized etc. If supported by the window manager, it will also have a common taskbar entry with its parent.

QDialog and QMainWindow widgets are by default top-level, even if a parent widget is specified in the constructor. This behavior is specified by the `Qt::WType_TopLevel` widget flag.

Access functions:

- bool isTopLevel () const

See also topLevelWidget(), isDialog(), isModal(), isPopup(), isDesktop(), and parentWidget().

### maximized : bool

This property holds whether this widget is maximized.

This property is only relevant for top-level widgets.

Note that due to limitations in some window-systems, this does not always report the expected results (e.g. if the user on X11 maximizes the window via the window manager, Qt has no way of distinguishing this from any other resize). This is expected to improve as window manager protocols evolve.

Access functions:

- bool isMaximized () const

See also windowState(), showMaximized(), visible, show(), hide(), showNormal(), and minimized.

### maximumHeight : int

This property holds the widget's maximum height.

This property corresponds to maximumSize().height().

Access functions:

- int maximumHeight () const
- void setMaximumHeight ( int maxh )

See also maximumSize and maximumWidth.

### maximumSize : QSize

This property holds the widget's maximum size.

The widget cannot be resized to a larger size than the maximum widget size.

Access functions:

- QSize maximumSize () const
- void setMaximumSize ( const QSize & )
- void setMaximumSize ( int maxw, int maxh )

See also maximumWidth(), maximumHeight(), setMaximumSize(), minimumSize(), and sizeIncrement().

### maximumWidth : int

This property holds the widget's maximum width.

This property corresponds to maximumSize().width().

Access functions:

- int maximumWidth () const
- void setMaximumWidth ( int maxw )

See also maximumSize and maximumHeight.

### microFocusHint : QRect

This property holds the currently set micro focus hint for this widget.

See the documentation of setMicroFocusHint() for more information.

Access functions:

- QRect microFocusHint () const

### minimized : bool

This property holds whether this widget is minimized (iconified).

This property is only relevant for top-level widgets.

Access functions:

- bool isMinimized () const

See also showMinimized(), visible, show(), hide(), showNormal(), and maximized.

### minimumHeight : int

This property holds the widget's minimum height.

This property corresponds to minimumSize().height().

Access functions:

- int minimumHeight () const
- void setMinimumHeight ( int minh )

See also minimumSize and minimumWidth.

### minimumSize : QSize

This property holds the widget's minimum size.

The widget cannot be resized to a smaller size than the minimum widget size. The widget's size is forced to the minimum size if the current size is smaller.

If you use a layout inside the widget, the minimum size will be set by the layout and not by setMinimumSize(), unless you set the layout's resize mode to QLayout::FreeResize.

QLayout::setResizeMode()

Access functions:

- QSize minimumSize () const
- void setMinimumSize ( const QSize & )
- void setMinimumSize ( int minw, int minh )

See also minimumWidth, minimumHeight, maximumSize, and sizeIncrement.

### minimumSizeHint : QSize

This property holds the recommended minimum size for the widget.

If the value of this property is an invalid size, no minimum size is recommended.

The default implementation of minimumSizeHint() returns an invalid size if there is no layout for this widget, and returns the layout's minimum size otherwise. Most built-in widgets reimplement minimumSizeHint().

QLayout will never resize a widget to a size smaller than minimumSizeHint.

Access functions:

- virtual QSize minimumSizeHint () const

See also QSize::isValid(), resize(), setMinimumSize(), and sizePolicy().

### minimumWidth : int

This property holds the widget's minimum width.

This property corresponds to minimumSize().width().

Access functions:

- int minimumWidth () const
- void setMinimumWidth ( int minw )

See also minimumSize and minimumHeight.

### mouseTracking : bool

This property holds whether mouse tracking is enabled for the widget.

If mouse tracking is disabled (the default), the widget only receives mouse move events when at least one mouse button is pressed while the mouse is being moved.

If mouse tracking is enabled, the widget receives mouse move events even if no buttons are pressed.

Access functions:

- bool hasMouseTracking () const
- void setMouseTracking ( bool enable )

See also mouseMoveEvent().

### palette : QPalette

This property holds the widget's palette.

As long as no special palette has been set, this is either a special palette for the widget class, the parent's palette or (if this widget is a top level widget), the default application palette.

Access functions:

- const QPalette & palette () const
- void setPalette ( const QPalette & )
- void setPalette ( const QPalette & p, bool b )

See also QApplication::palette().

### pos : QPoint

This property holds the position of the widget within its parent widget.

If the widget is a top-level widget, the position is that of the widget on the desktop, including its frame.

When changing the position, the widget, if visible, receives a move event (moveEvent()) immediately. If the widget is not currently visible, it is guaranteed to receive an event before it is shown.

move() is virtual, and all other overloaded move() implementations in Qt call it.

Warning: Calling move() or setGeometry() inside moveEvent() can lead to infinite recursion.

See the Window Geometry documentation for an overview of top-level widget geometry.

Access functions:

- QPoint pos () const
- void move ( int x, int y )
- void move ( const QPoint & )

See also frameGeometry, size, x(), and y().

### rect : QRect

This property holds the internal geometry of the widget excluding any window frame.

The rect property equals QRect(0, 0, width(), height()).

See the Window Geometry documentation for an overview of top-level widget geometry.

Access functions:

- QRect rect () const

See also size.

### shown : bool

This property holds whether the widget is shown.

If true, the widget is visible or would become visible if all its ancestors became visible.

Access functions:

- bool isShown () const
- void setShown ( bool show )

See also hide(), show(), isVisible(), isVisibleTo(), and hidden.

### size : QSize

This property holds the size of the widget excluding any window frame.

If the widget is visible when it is being resized, it receives a resize event (resizeEvent()) immediately. If the widget is not currently visible, it is guaranteed to receive an event before it is shown.

The size is adjusted if it lies outside the range defined by minimumSize() and maximumSize(). For top-level widgets, the minimum size is always at least QSize(1, 1), and it might be larger, depending on the window manager.

If you want a top-level window to have a fixed size, call setResizeMode(QLayout::FreeResize) on its layout.

resize() is virtual, and all other overloaded resize() implementations in Qt call it.

Warning: Calling resize() or setGeometry() inside resizeEvent() can lead to infinite recursion.

Access functions:

- QSize size () const
- void resize ( int w, int h )
- void resize ( const QSize & )

See also pos, geometry, minimumSize, maximumSize, and resizeEvent().

### sizeHint : QSize

This property holds the recommended size for the widget.

If the value of this property is an invalid size, no size is recommended.

The default implementation of sizeHint() returns an invalid size if there is no layout for this widget, and returns the layout's preferred size otherwise.

Access functions:

- virtual QSize sizeHint () const

See also QSize::isValid(), minimumSizeHint(), sizePolicy(), setMinimumSize(), and updateGeometry().

### sizeIncrement : QSize

This property holds the size increment of the widget.

When the user resizes the window, the size will move in steps of sizeIncrement().width() pixels horizontally and sizeIncrement.height() pixels vertically, with baseSize() as the basis. Preferred widget sizes are for non-negative integers i and j:

        width = baseSize().width() + i * sizeIncrement().width();
        height = baseSize().height() + j * sizeIncrement().height();

Note that while you can set the size increment for all widgets, it only affects top-level widgets.

Warning: The size increment has no effect under Windows, and may be disregarded by the window manager on X.

Access functions:

- QSize sizeIncrement () const
- void setSizeIncrement ( const QSize & )
- void setSizeIncrement ( int w, int h )

See also size, minimumSize, and maximumSize.

### sizePolicy : QSizePolicy

This property holds the default layout behavior of the widget.

If there is a QLayout that manages this widget's children, the size policy specified by that layout is used. If there is no such QLayout, the result of this function is used.

The default policy is Preferred/Preferred, which means that the widget can be freely resized, but prefers to be the size sizeHint() returns. Button-like widgets set the size policy to specify that they may stretch horizontally, but are fixed vertically. The same applies to lineedit controls (such as QLineEdit, QSpinBox or an editable QComboBox) and other horizontally orientated widgets (such as QProgressBar). QToolButton's are normally square, so they allow growth in both directions. Widgets that support different directions (such as QSlider, QScrollBar or QHeader) specify stretching in the respective direction only. Widgets that can provide scrollbars (usually subclasses of QScrollView) tend to specify that they can use additional space, and that they can make do with less than sizeHint().

Access functions:

- virtual QSizePolicy sizePolicy () const
- void setSizePolicy ( QSizePolicy )
- void setSizePolicy ( QSizePolicy::SizeType hor, QSizePolicy::SizeType ver, bool hfw = false )

See also sizeHint(), QLayout, QSizePolicy, and updateGeometry().

### statusTip : QString

This property holds the widget's status tip.

Access functions:

- QString statusTip () const
- void setStatusTip ( const QString & )

See also toolTip and whatsThis.

### toolTip : QString

This property holds the widget's tooltip.

Access functions:

- QString toolTip () const
- void setToolTip ( const QString & )

See also QToolTip, statusTip, and whatsThis.

### updatesEnabled : bool

This property holds whether updates are enabled.

Calling update() and repaint() has no effect if updates are disabled. Paint events from the window system are processed normally even if updates are disabled.

setUpdatesEnabled() is normally used to disable updates for a short period of time, for instance to avoid screen flicker during large changes.

Example:

        setUpdatesEnabled(false);
        bigVisualChanges();
        setUpdatesEnabled(true);
        repaint();

Access functions:

- bool isUpdatesEnabled () const
- void setUpdatesEnabled ( bool enable )

See also update(), repaint(), and paintEvent().

### visible : bool

This property holds whether the widget is visible.

Calling show() sets the widget to visible status if all its parent widgets up to the top-level widget are visible. If an ancestor is not visible, the widget won't become visible until all its ancestors are shown.

Calling hide() hides a widget explicitly. An explicitly hidden widget will never become visible, even if all its ancestors become visible, unless you show it.

A widget receives show and hide events when its visibility status changes. Between a hide and a show event, there is no need to waste CPU cycles preparing or displaying information to the user. A video application, for example, might simply stop generating new frames.

A widget that happens to be obscured by other windows on the screen is considered to be visible. The same applies to iconified top-level widgets and windows that exist on another virtual desktop (on platforms that support this concept). A widget receives spontaneous show and hide events when its mapping status is changed by the window system, e.g. a spontaneous hide event when the user minimizes the window, and a spontaneous show event when the window is restored again.

Access functions:

- bool isVisible () const

See also show(), hide(), isHidden(), isVisibleTo(), isMinimized(), showEvent(), and hideEvent().

### whatsThis : QString

This property holds the widget's What's This help text.

Access functions:

- QString whatsThis () const
- void setWhatsThis ( const QString & )

See also QWhatsThis, QWidget::toolTip, and QWidget::statusTip.

### width : int

This property holds the width of the widget excluding any window frame.

See the Window Geometry documentation for an overview of top-level widget geometry.

Access functions:

- int width () const

See also geometry, height, and size.

### windowIcon : QPixmap

This property holds the widget's icon.

This property only makes sense for top-level widgets. If no icon has been set, windowIcon() returns the application icon.

Access functions:

- const QPixmap & windowIcon () const
- void setWindowIcon ( const QPixmap & )

See also windowIconText, windowTitle, and Setting the Application Icon.

### windowIconText : QString

This property holds the widget's icon text.

This property only makes sense for top-level widgets. If no icon text has been set, this functions returns an empty string.

Access functions:

- QString windowIconText () const
- void setWindowIconText ( const QString & )

See also windowIcon and windowTitle.

### windowOpacity : double

This property holds the level of opacity for the window.

The valid range of opacity is from 1.0 (completely opaque) to 0.0 (completely transparent).

By default the value of this property is 1.0.

This feature is only present on Mac OS X and Windows 2000 and up.

Warning: Changing this property from opaque to transparent might issue a paint event that needs to be processed before the window is displayed correctly. This affects mainly the use of QPixmap::grabWindow(). Also note that semi-transparent windows update and resize significantly slower than opaque windows.

Access functions:

- double windowOpacity () const
- void setWindowOpacity ( double level )

### windowTitle : QString

This property holds the window title (caption).

This property only makes sense for top-level widgets. If no caption has been set, the title is an empty string.

Access functions:

- QString windowTitle () const
- void setWindowTitle ( const QString & )

See also windowIcon and windowIconText.

### x : int

This property holds the x coordinate of the widget relative to its parent including any window frame.

See the Window Geometry documentation for an overview of top-level widget geometry.

Access functions:

- int x () const

See also frameGeometry, y, and pos.

### y : int

This property holds the y coordinate of the widget relative to its parent and including any window frame.

See the Window Geometry documentation for an overview of top-level widget geometry.

Access functions:

- int y () const

See also frameGeometry, x, and pos.

## Member Function Documentation

### QWidget::QWidget ( QWidget * parent = 0, Qt::WFlags f = 0 )

Constructs a widget which is a child of parent, with widget flags set to f.

If parent is 0, the new widget becomes a top-level window. If parent is another widget, this widget becomes a child window inside parent. The new widget is deleted when its parent is deleted.

The widget flags argument, f, is normally 0, but it can be set to customize the window frame of a top-level widget (i.e. parent must be 0). To customize the frame, set the `Qt::WStyle_Customize` flag OR'ed with any of the Qt::WFlags.

If you add a child widget to an already visible widget you must explicitly show the child to make it visible.

Note that the X11 version of Qt may not be able to deliver all combinations of style flags on all systems. This is because on X11, Qt can only ask the window manager, and the window manager can override the application's settings. On Windows, Qt can set whatever flags you want.

### QWidget::~QWidget ()

Destroys the widget.

All this widget's children are deleted first. The application exits if this widget is the main widget.

### void QWidget::actionEvent ( QActionEvent * event ) `[virtual protected]`

This event handler is called with the given event whenever the widget's actions are changed.

See also addAction(), insertAction(), removeAction(), actions(), and QActionEvent.

### QList<QAction *> QWidget::actions () const

Returns the (possibly empty) list of this widget's actions.

### void QWidget::addAction ( QAction * action )

Appends the action action to this widget's list of actions.

All QWidgets have list of QActions, however they can be represented graphically in many different ways. The default use of the QAction list (as returned by actions()) is to create a context QMenu.

See also removeAction() and QMenu.

### void QWidget::addActions ( QList<QAction *> actions )

Appends the actions actions to this widget's list of actions.

See also removeAction(), QMenu, and addAction().

### void QWidget::adjustSize ()

Adjusts the size of the widget to fit the contents.

Uses sizeHint() if valid (i.e if the size hint's width and height are >= 0), otherwise sets the size to the children rectangle (the union of all child widget geometries). For toplevel widgets, the function also takes the screen size into account.

See also sizeHint() and childrenRect().

### QPalette::ColorRole QWidget::backgroundRole () const

Returns the background role.

See also setBackgroundRole() and foregroundRole().

### void QWidget::changeEvent ( QEvent * e ) `[virtual protected]`

This event handler can be reimplemented to handle state changes.

The state being changed in this event can be retrieved through event e.

### QWidget * QWidget::childAt ( int x, int y ) const

Returns the visible child widget at pixel position (x, y) in the widget's own coordinate system. If there is no visible child widget at the specified position, returns 0.

### QWidget * QWidget::childAt ( const QPoint & p ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the visible child widget at point p in the widget's own coordinate system.

### void QWidget::clearFocus ()

Takes keyboard input focus from the widget.

If the widget has active focus, a focus out event is sent to this widget to tell it that it is about to lose the focus.

This widget must enable focus setting in order to get the keyboard input focus, i.e. it must call setFocusPolicy().

See also hasFocus(), setFocus(), focusInEvent(), focusOutEvent(), setFocusPolicy(), and QApplication::focusWidget().

### void QWidget::clearMask ()

Removes any mask set by setMask().

See also setMask().

### void QWidget::clearWFlags ( Qt::WFlags f ) `[protected]`

Clears the widget flags f.

Widget flags are a combination of Qt::WindowFlags.

See also testWFlags(), getWFlags(), and setWFlags().

### QRegion QWidget::clipRegion () const

Returns the unobscured region where paint events can occur.

For visible widgets, this is an approximation of the area not covered by other widgets; otherwise, this is an empty region.

The repaint() function calls this function if necessary, so in general you do not need to call it.

### bool QWidget::close () `[slot]`

Closes this widget. Returns true if the widget was closed; otherwise returns false.

First it sends the widget a QCloseEvent. The widget is hidden if it accepts the close event. If it ignores the event, nothing happens. The default implementation of QWidget::closeEvent() accepts the close event.

If the widget has the `Qt::WA_DeleteOnClose` flag, the widget is also deleted. A close events is delivered to the widget no matter if the widget is visible or not.

The QApplication::lastWindowClosed() signal is emitted when the last visible top level widget is closed.

### void QWidget::closeEvent ( QCloseEvent * e ) `[virtual protected]`

This event handler, for event e, can be reimplemented in a subclass to receive widget close events.

See also event(), hide(), close(), and QCloseEvent.

### QSize QWidget::contentsMarginSize () const

Returns the size of the widget's margin. This is the same as size() - contentsRect().size().

See also setContentsMargins() and contentsRect().

### QRect QWidget::contentsRect () const

Returns the area inside the widget's margins.

See also setContentsMargins() and contentsMarginSize().

### void QWidget::contextMenuEvent ( QContextMenuEvent * e ) `[virtual protected]`

This event handler, for event e, can be reimplemented in a subclass to receive widget context menu events.

The default implementation calls e->ignore(), which rejects the context event. See the QContextMenuEvent documentation for more details.

See also event() and QContextMenuEvent.

### void QWidget::create ( WId window = 0, bool initializeWindow = true, bool destroyOldWindow = true ) `[protected]`

Creates a new widget window if window is 0, otherwise sets the widget's window to window.

Initializes the window (sets the geometry etc.) if initializeWindow is true. If initializeWindow is false, no initialization is performed. This parameter only makes sense if window is a valid window.

Destroys the old window if destroyOldWindow is true. If destroyOldWindow is false, you are responsible for destroying the window yourself (using platform native code).

The QWidget constructor calls create(0,true,true) to create a window for this widget.

### void QWidget::destroy ( bool destroyWindow = true, bool destroySubWindows = true ) `[protected]`

Frees up window system resources. Destroys the widget window if destroyWindow is true.

destroy() calls itself recursively for all the child widgets, passing destroySubWindows for the destroyWindow parameter. To have more control over destruction of subwidgets, destroy subwidgets selectively first.

This function is usually called from the QWidget destructor.

### void QWidget::dragEnterEvent ( QDragEnterEvent * event ) `[virtual protected]`

This event handler is called when a drag is in progress and the mouse enters this widget. The event is passed in the event parameter.

See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.

See also QTextDrag, QImageDrag, and QDragEnterEvent.

### void QWidget::dragLeaveEvent ( QDragLeaveEvent * event ) `[virtual protected]`

This event handler is called when a drag is in progress and the mouse leaves this widget. The event is passed in the event parameter.

See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.

See also QTextDrag, QImageDrag, and QDragLeaveEvent.

### void QWidget::dragMoveEvent ( QDragMoveEvent * event ) `[virtual protected]`

This event handler is called if a drag is in progress, and when any of the following conditions occurs: the cursor enters this widget, the cursor moves within this widget, or a modifier key is pressed on the keyboard while this widget has the focus. The event is passed in the event parameter.

See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.

See also QTextDrag, QImageDrag, and QDragMoveEvent.

### void QWidget::dropEvent ( QDropEvent * event ) `[virtual protected]`

This event handler is called when the drag is dropped on this widget which are passed in the event parameter.

See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.

See also QTextDrag, QImageDrag, and QDropEvent.

### void QWidget::ensurePolished () const

Ensures delayed initialization of a widget and its children.

This function will be called after a widget has been fully created and before it is shown the very first time. Children will be polished after the polishEvent() handler for this widget is called.

Polishing is useful for final initialization which depends on having an instantiated widget. This is something a constructor cannot guarantee since the initialization of the subclasses might not be finished.

For widgets, this function makes sure the widget has a proper font and palette and QApplication::polish() has been called.

If you need to change some settings when a widget is polished, use polishEvent().

See also polishEvent() and QApplication::polish().

### void QWidget::enterEvent ( QEvent * event ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive widget enter events which are passed in the event parameter.

An event is sent to the widget when the mouse cursor enters the widget.

See also leaveEvent(), mouseMoveEvent(), and event().

### bool QWidget::event ( QEvent * e ) `[virtual protected]`

This is the main event handler; it handles event e. You can reimplement this function in a subclass, but we recommend using one of the specialized event handlers instead.

The main event handler first passes an event through all event filters that have been installed. If none of the filters intercept the event, it calls one of the specialized event handlers.

Key press and release events are treated differently from other events. event() checks for Tab and Shift+Tab and tries to move the focus appropriately. If there is no widget to move the focus to (or the key press is not Tab or Shift+Tab), event() calls keyPressEvent().

This function returns true if it is able to pass the event over to someone (i.e. someone wanted the event); otherwise returns false.

Reimplemented from QObject.

See also closeEvent(), focusInEvent(), focusOutEvent(), enterEvent(), keyPressEvent(), keyReleaseEvent(), leaveEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), moveEvent(), paintEvent(), resizeEvent(), QObject::event(), and QObject::timerEvent().

### QWidget * QWidget::find ( WId id ) `[static]`

Returns a pointer to the widget with window identifer/handle id.

The window identifier type depends on the underlying window system, see `qwindowdefs.h` for the actual definition. If there is no widget with this identifier, 0 is returned.

### void QWidget::focusInEvent ( QFocusEvent * event ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive keyboard focus events (focus received) for the widget. The event is passed in the event parameter

A widget normally must setFocusPolicy() to something other than `Qt::NoFocus` in order to receive focus events. (Note that the application programmer can call setFocus() on any widget, even those that do not normally accept focus.)

The default implementation updates the widget (except for top-level widgets that do not specify a focusPolicy()). It also calls setMicroFocusHint(), hinting any system-specific input tools about the focus of the user's attention.

See also focusOutEvent(), setFocusPolicy(), keyPressEvent(), keyReleaseEvent(), event(), and QFocusEvent.

### bool QWidget::focusNextPrevChild ( bool next ) `[virtual protected]`

Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if is can find a new widget and false if it can't,

If next is true, this function searches "forwards", if next is false, it searches "backwards".

Sometimes, you will want to reimplement this function. For example, a web browser might reimplement it to move its "current active link" forwards or backwards, and call QWidget::focusNextPrevChild() only when it reaches the last or first link on the "page".

Child widgets call focusNextPrevChild() on their parent widgets, but only the top-level widget decides where to redirect focus. By overriding this method for an object, you thus gain control of focus traversal for all child widgets.

### void QWidget::focusOutEvent ( QFocusEvent * event ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) for the widget. The events is passed in the event parameter.

A widget normally must setFocusPolicy() to something other than `Qt::NoFocus` in order to receive focus events. (Note that the application programmer can call setFocus() on any widget, even those that do not normally accept focus.)

The default implementation updates the widget (except for top-level widgets that do not specify a focusPolicy()). It also calls setMicroFocusHint(), hinting any system-specific input tools about the focus of the user's attention.

See also focusInEvent(), setFocusPolicy(), keyPressEvent(), keyReleaseEvent(), event(), and QFocusEvent.

### QWidget * QWidget::focusProxy () const

Returns the focus proxy, or 0 if there is no focus proxy.

See also setFocusProxy().

### QWidget * QWidget::focusWidget () const

Returns the last child of this widget that setFocus had been called on. For top level widgets this is the widget that will get focus in case this window gets activated

This is not the same as QApplication::focusWidget(), which returns the focus widget in the currently active window.

### QFontInfo QWidget::fontInfo () const

Returns the font info for the widget's current font. Equivalent to QFontInto(widget->font()).

See also font(), fontMetrics(), and setFont().

### QFontMetrics QWidget::fontMetrics () const

Returns the font metrics for the widget's current font. Equivalent to QFontMetrics(widget->font()).

See also font(), fontInfo(), and setFont().

### QPalette::ColorRole QWidget::foregroundRole () const

Returns the foreground role.

If no explicit foreground role is set, returns a role that contrasts with the backgroundRole().

See also setForegroundRole() and backgroundRole().

### HDC QWidget::getDC () const `[virtual]`

Returns the window system handle of the widget, for low-level access. Using this function is not portable.

An HDC aquired with getDC() has to be released with releaseDC().

Reimplemented from QPaintDevice.

### Qt::WFlags QWidget::getWFlags () const `[protected]`

Returns the widget flags for this this widget.

Widget flags are a combination of Qt::WindowFlags.

See also testWFlags(), setWFlags(), and clearWFlags().

### void QWidget::grabKeyboard ()

Grabs the keyboard input.

This widget reveives all keyboard events until releaseKeyboard() is called; other widgets get no keyboard events at all. Mouse events are not affected. Use grabMouse() if you want to grab that.

The focus widget is not affected, except that it doesn't receive any keyboard events. setFocus() moves the focus as usual, but the new focus widget receives keyboard events only after releaseKeyboard() is called.

If a different widget is currently grabbing keyboard input, that widget's grab is released first.

See also releaseKeyboard(), grabMouse(), releaseMouse(), and focusWidget().

### void QWidget::grabMouse ()

Grabs the mouse input.

This widget receives all mouse events until releaseMouse() is called; other widgets get no mouse events at all. Keyboard events are not affected. Use grabKeyboard() if you want to grab that.

Warning: Bugs in mouse-grabbing applications very often lock the terminal. Use this function with extreme caution, and consider using the `-nograb` command line option while debugging.

It is almost never necessary to grab the mouse when using Qt, as Qt grabs and releases it sensibly. In particular, Qt grabs the mouse when a mouse button is pressed and keeps it until the last button is released.

Note that only visible widgets can grab mouse input. If isVisible() returns false for a widget, that widget cannot call grabMouse().

focusWidget()

See also releaseMouse(), grabKeyboard(), releaseKeyboard(), and grabKeyboard().

### void QWidget::grabMouse ( const QCursor & cursor )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Grabs the mouse input and changes the cursor shape.

The cursor will assume shape cursor (for as long as the mouse focus is grabbed) and this widget will be the only one to receive mouse events until releaseMouse() is called().

Warning: Grabbing the mouse might lock the terminal.

See also releaseMouse(), grabKeyboard(), releaseKeyboard(), and setCursor().

### int QWidget::grabShortcut ( const QKeySequence & key, Qt::ShortcutContext context = Qt::ShortcutOnActiveWindow )

Adds a shortcut to Qt's shortcut system that watches for the given key sequence in the given context. If the context is not `OnApplication`, the shortcut is local to this widget; otherwise it applies to the application as a whole.

If the same key sequence has been grabbed by several widgets, when the key sequence occurs a QEvent::Shortcut event is sent to all the widgets to which it applies in a non-deterministic order, but with the ``ambiguous'' flag set to true.

Warning: You should not normally need to use this function; instead create QActions with the shortcut key sequences you require (if you also want equivalent menu options and toolbar buttons), or create QShortcuts if you just need key sequences. Both QAction and QShortcut handle all the event filtering for you, and provide signals which are triggered when the user triggers the key sequence, so are much easier to use than this low-level function.

See also releaseShortcut() and setShortcutEnabled().

### int QWidget::heightForWidth ( int w ) const `[virtual]`

Returns the preferred height for this widget, given the width w. The default implementation returns 0, indicating that the preferred height does not depend on the width.

Warning: Does not look at the widget's layout.

### void QWidget::hide () `[virtual slot]`

Hides the widget.

You almost never have to reimplement this function. If you need to do something after a widget is hidden, use hideEvent() instead.

See also hideEvent(), isHidden(), show(), showMinimized(), isVisible(), and close().

### void QWidget::hideEvent ( QHideEvent * event ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive widget hide events. The event is passed in the event parameter.

Hide events are sent to widgets immediately after they have been hidden.

See also event() and QHideEvent.

### void QWidget::imComposeEvent ( QIMEvent * e ) `[virtual protected]`

This event handler, for event e, can be reimplemented in a subclass to receive Input Method composition events. This handler is called when the user has entered some text using an Input Method.

The default implementation calls e->ignore(), which rejects the Input Method event. See the QIMEvent documentation for more details.

See also event() and QIMEvent.

### void QWidget::imEndEvent ( QIMEvent * e ) `[virtual protected]`

This event handler, for event e, can be reimplemented in a subclass to receive Input Method composition events. This handler is called when the user has finished inputting text via an Input Method.

The default implementation calls e->ignore(), which rejects the Input Method event. See the QIMEvent documentation for more details.

See also event() and QIMEvent.

### void QWidget::imStartEvent ( QIMEvent * e ) `[virtual protected]`

This event handler, for event e, can be reimplemented in a subclass to receive Input Method composition events. This handler is called when the user begins entering text using an Input Method.

The default implementation calls e->ignore(), which rejects the Input Method event. See the QIMEvent documentation for more details.

See also event() and QIMEvent.

### void QWidget::insertAction ( QAction * before, QAction * action )

Inserts the action action to this widget's list of actions, before the action before. It appends the action if before is 0 or before is not a valid action for this widget.

See also addAction().

### void QWidget::insertActions ( QAction * before, QList<QAction *> actions )

Inserts the actions actions to this widget's list of actions, before the action before. It appends the action if before is 0 or before is not a valid action for this widget.

See also removeAction(), QMenu, and insertAction().

### bool QWidget::isEnabledTo ( QWidget * ancestor ) const

Returns true if this widget would become enabled if ancestor is enabled; otherwise returns false.

This is the case if neither the widget itself nor every parent up to but excluding ancestor has been explicitly disabled.

isEnabledTo(0) is equivalent to isEnabled().

See also setEnabled() and enabled.

### bool QWidget::isVisibleTo ( QWidget * ancestor ) const

Returns true if this widget would become visible if ancestor is shown; otherwise returns false.

The true case occurs if neither the widget itself nor any parent up to but excluding ancestor has been explicitly hidden.

This function will still return true if the widget is obscured by other windows on the screen, but could be physically visible if it or they were to be moved.

isVisibleTo(0) is identical to isVisible().

See also show(), hide(), and isVisible().

### void QWidget::keyPressEvent ( QKeyEvent * e ) `[virtual protected]`

This event handler, for event e, can be reimplemented in a subclass to receive key press events for the widget.

A widget must call setFocusPolicy() to accept focus initially and have focus in order to receive a key press event.

If you reimplement this handler, it is very important that you ignore() the event if you do not understand it, so that the widget's parent can interpret it.

The default implementation closes popup widgets if the user presses Esc. Otherwise the event is ignored.

See also keyReleaseEvent(), QKeyEvent::ignore(), setFocusPolicy(), focusInEvent(), focusOutEvent(), event(), and QKeyEvent.

### void QWidget::keyReleaseEvent ( QKeyEvent * e ) `[virtual protected]`

This event handler, for event e, can be reimplemented in a subclass to receive key release events for the widget.

A widget must accept focus initially and have focus in order to receive a key release event.

If you reimplement this handler, it is very important that you ignore() the release if you do not understand it, so that the widget's parent can interpret it.

The default implementation ignores the event.

See also keyPressEvent(), QKeyEvent::ignore(), setFocusPolicy(), focusInEvent(), focusOutEvent(), event(), and QKeyEvent.

### QWidget * QWidget::keyboardGrabber () `[static]`

Returns the widget that is currently grabbing the keyboard input.

If no widget in this application is currently grabbing the keyboard, 0 is returned.

See also grabMouse() and mouseGrabber().

### QLayout * QWidget::layout () const

Returns the layout engine that manages the geometry of this widget's children.

If the widget does not have a layout, layout() returns 0.

See also sizePolicy().

### void QWidget::leaveEvent ( QEvent * event ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive widget leave events which are passed in the event parameter.

A leave event is sent to the widget when the mouse cursor leaves the widget.

See also enterEvent(), mouseMoveEvent(), and event().

### void QWidget::lower () `[slot]`

Lowers the widget to the bottom of the parent widget's stack.

After this call the widget will be visually behind (and therefore obscured by) any overlapping sibling widgets.

See also raise() and stackUnder().

### bool QWidget::macEvent ( EventHandlerCallRef caller, EventRef event ) `[virtual protected]`

This special event handler can be reimplemented in a subclass to receive native Macintosh events which are passed from the caller with the event details in the event parameter.

In your reimplementation of this function, if you want to stop the event being handled by Qt, return true. If you return false, this native event is passed back to Qt, which translates the event into a Qt event and sends it to the widget.

Warning: This function is not portable.

See also QApplication::macEventFilter().

### QPoint QWidget::mapFrom ( QWidget * parent, const QPoint & pos ) const

Translates the widget coordinate pos from the coordinate system of parent to this widget's coordinate system. The parent must not be 0 and must be a parent of the calling widget.

See also mapTo(), mapFromParent(), mapFromGlobal(), and underMouse().

### QPoint QWidget::mapFromGlobal ( const QPoint & pos ) const

Translates the global screen coordinate pos to widget coordinates.

See also mapToGlobal(), mapFrom(), and mapFromParent().

### QPoint QWidget::mapFromParent ( const QPoint & pos ) const

Translates the parent widget coordinate pos to widget coordinates.

Same as mapFromGlobal() if the widget has no parent.

See also mapToParent(), mapFrom(), mapFromGlobal(), and underMouse().

### QPoint QWidget::mapTo ( QWidget * parent, const QPoint & pos ) const

Translates the widget coordinate pos to the coordinate system of parent. The parent must not be 0 and must be a parent of the calling widget.

See also mapFrom(), mapToParent(), mapToGlobal(), and underMouse().

### QPoint QWidget::mapToGlobal ( const QPoint & pos ) const

Translates the widget coordinate pos to global screen coordinates. For example, `mapToGlobal(QPoint(0,0))` would give the global coordinates of the top-left pixel of the widget.

See also mapFromGlobal(), mapTo(), and mapToParent().

### QPoint QWidget::mapToParent ( const QPoint & pos ) const

Translates the widget coordinate pos to a coordinate in the parent widget.

Same as mapToGlobal() if the widget has no parent.

See also mapFromParent(), mapTo(), mapToGlobal(), and underMouse().

### QRegion QWidget::mask () const

Returns the mask currently set on a widget. If no mask is set the return value will be an empty region.

See also setMask(), clearMask(), and QRegion::isEmpty().

### int QWidget::metric ( int m ) const `[virtual protected]`

Internal implementation of the virtual QPaintDevice::metric() function.

Use the QPaintDeviceMetrics class instead.

m is the metric to get.

Reimplemented from QPaintDevice.

### void QWidget::mouseDoubleClickEvent ( QMouseEvent * e ) `[virtual protected]`

This event handler, for event e, can be reimplemented in a subclass to receive mouse double click events for the widget.

The default implementation generates a normal mouse press event.

Note that the widgets gets a mousePressEvent() and a mouseReleaseEvent() before the mouseDoubleClickEvent().

See also mousePressEvent(), mouseReleaseEvent(), mouseMoveEvent(), event(), and QMouseEvent.

### QWidget * QWidget::mouseGrabber () `[static]`

Returns the widget that is currently grabbing the mouse input.

If no widget in this application is currently grabbing the mouse, 0 is returned.

See also grabMouse() and keyboardGrabber().

### void QWidget::mouseMoveEvent ( QMouseEvent * e ) `[virtual protected]`

This event handler, for event e, can be reimplemented in a subclass to receive mouse move events for the widget.

If mouse tracking is switched off, mouse move events only occur if a mouse button is pressed while the mouse is being moved. If mouse tracking is switched on, mouse move events occur even if no mouse button is pressed.

QMouseEvent::pos() reports the position of the mouse cursor, relative to this widget. For press and release events, the position is usually the same as the position of the last mouse move event, but it might be different if the user's hand shakes. This is a feature of the underlying window system, not Qt.

See also setMouseTracking(), mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), event(), and QMouseEvent.

### void QWidget::mousePressEvent ( QMouseEvent * e ) `[virtual protected]`

This event handler, for event e, can be reimplemented in a subclass to receive mouse press events for the widget.

If you create new widgets in the mousePressEvent() the mouseReleaseEvent() may not end up where you expect, depending on the underlying window system (or X11 window manager), the widgets' location and maybe more.

The default implementation implements the closing of popup widgets when you click outside the window. For other widget types it does nothing.

See also mouseReleaseEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), event(), and QMouseEvent.

### void QWidget::mouseReleaseEvent ( QMouseEvent * e ) `[virtual protected]`

This event handler, for event e, can be reimplemented in a subclass to receive mouse release events for the widget.

See also mousePressEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), event(), and QMouseEvent.

### void QWidget::moveEvent ( QMoveEvent * event ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive widget move events which are passed in the event parameter. When the widget receives this event, it is already at the new position.

The old position is accessible through QMoveEvent::oldPos().

See also resizeEvent(), event(), move(), and QMoveEvent.

### QWidget * QWidget::nextInFocusChain () const

Returns the next widget in this widget's focus chain.

### QPaintEngine * QWidget::paintEngine () const `[virtual]`

Returns the widget's paint engine. (This defaults to the QQWSPaintEngine.)

Reimplemented from QPaintDevice.

### void QWidget::paintEvent ( QPaintEvent * event ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive paint events which are passed in the event parameter.

A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint() or update(), or because the widget was obscured and has now been uncovered, or for many other reasons.

Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QCanvas do this, for example.

Qt also tries to speed up painting by merging multiple paint events into one. When update() is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::unite()). repaint() does not permit this optimization, so we suggest using update() when possible.

When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background. There are a couple of exceptions and QPaintEvent::erased() tells you whether the widget has been erased or not.

The background can be set using setBackground() or setBackgroundRole().

From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent() to avoid flicker.

See also event(), repaint(), update(), QPainter, QPixmap, and QPaintEvent.

### QWidget * QWidget::parentWidget () const

Returns the parent of this widget, or 0 if it does not have any parent widget.

### void QWidget::polishEvent ( QEvent * event ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive widget polish events passed in the event parameter.

See also ensurePolished() and QApplication::polish().

### bool QWidget::qwsEvent ( QWSEvent * event ) `[virtual protected]`

This special event handler can be reimplemented in a subclass to receive native Qt/Embedded events which are passed in the event parameter.

In your reimplementation of this function, if you want to stop the event being handled by Qt, return true. If you return false, this native event is passed back to Qt, which translates the event into a Qt event and sends it to the widget.

Warning: This function is not portable.

See also QApplication::qwsEventFilter().

### void QWidget::raise () `[slot]`

Raises this widget to the top of the parent widget's stack.

After this call the widget will be visually in front of any overlapping sibling widgets.

See also lower() and stackUnder().

### void QWidget::releaseDC ( HDC hdc ) const `[virtual]`

Releases the HDC aquired by a previous call to getDC(). Using this function is not portable.

Reimplemented from QPaintDevice.

### void QWidget::releaseKeyboard ()

Releases the keyboard grab.

See also grabKeyboard(), grabMouse(), and releaseMouse().

### void QWidget::releaseMouse ()

Releases the mouse grab.

See also grabMouse(), grabKeyboard(), and releaseKeyboard().

### void QWidget::releaseShortcut ( int id )

Removes the shortcut with the given id from Qt's shortcut system. The widget will no longer receive QEvent::Shortcut events for the shortcut's key sequence (unless it has other shortcuts with the same key sequence).

Warning: You should not normally need to use this function since Qt's shortcut system removes shortcuts automatically when their parent widget is destroyed. It is best to use QAction or QShortcut to handle shortcuts, since they are easier to use than this low-level function. Note also that this is an expensive operation.

See also grabShortcut() and setShortcutEnabled().

### void QWidget::removeAction ( QAction * action )

Removes the action action from this widget's list of actions.

### void QWidget::repaint () `[slot]`

Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the widget is hidden.

We suggest only using repaint() if you need an immediate repaint, for example during animation. In almost all circumstances update() is better, as it permits Qt to optimize for speed and minimize flicker.

Warning: If you call repaint() in a function which may itself be called from paintEvent(), you may get infinite recursion. The update() function never causes recursion.

See also update(), paintEvent(), and setUpdatesEnabled().

### void QWidget::repaint ( int x, int y, int w, int h )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This version repaints a rectangle (x, y, w, h) inside the widget.

If w is negative, it is replaced with `width() - x`, and if h is negative, it is replaced width `height() - y`.

### void QWidget::repaint ( const QRect & r )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This version repaints a rectangle r inside the widget.

### void QWidget::repaint ( const QRegion & rgn )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This version repaints a region rgn inside the widget.

### void QWidget::resetInputContext () `[protected]`

This function is called when the user finishes input composition, e.g. changes focus to another widget, moves the cursor, etc.

### void QWidget::resizeEvent ( QResizeEvent * event ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive widget resize events which are passed in the event parameter. When resizeEvent() is called, the widget already has its new geometry. The old size is accessible through QResizeEvent::oldSize().

The widget will be erased and receive a paint event immediately after processing the resize event. No drawing need be (or should be) done inside this handler.

Widgets that have been created with the `Qt::WNoAutoErase` flag will not be erased. Nevertheless, they will receive a paint event for their entire area afterwards. Again, no drawing needs to be done inside this handler.

The default implementation calls updateMask() if the widget has automatic masking enabled.

See also moveEvent(), event(), resize(), QResizeEvent, and paintEvent().

### void QWidget::scroll ( int dx, int dy )

Scrolls the widget including its children dx pixels to the right and dy downwards. Both dx and dy may be negative.

After scrolling, scroll() sends a paint event for the the part that is read but not written. For example, when scrolling 10 pixels rightwards, the leftmost ten pixels of the widget need repainting. The paint event may be delivered immediately or later, depending on some heuristics (note that you might have to force processing of paint events using QApplication::sendPostedEvents() when using scroll() and move() in combination).

See also QScrollView and bitBlt().

### void QWidget::scroll ( int dx, int dy, const QRect & r )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This version only scrolls r and does not move the children of the widget.

If r is empty or invalid, the result is undefined.

See also QScrollView and bitBlt().

### void QWidget::setActiveWindow ()

Sets the top-level widget containing this widget to be the active window.

An active window is a visible top-level window that has the keyboard input focus.

This function performs the same operation as clicking the mouse on the title bar of a top-level window. On X11, the result depends on the Window Manager. If you want to ensure that the window is stacked on top as well you should also call raise(). Note that the window must be visible, otherwise setActiveWindow() has no effect.

On Windows, if you are calling this when the application is not currently the active one then it will not make it the active window. It will flash the task bar entry blue to indicate that the window has done something. This is because Microsoft do not allow an application to interrupt what the user is currently doing in another application.

See also isActiveWindow(), topLevelWidget(), and show().

### void QWidget::setAttribute ( Qt::WidgetAttribute attribute, bool on = true )

Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.

See also testAttribute().

### void QWidget::setBackgroundRole ( QPalette::ColorRole role )

Sets the background role of the widget to role.

See also backgroundRole() and foregroundRole().

### void QWidget::setContentsMargins ( int left, int top, int right, int bottom )

Sets the margins around the contents of the widget to have the sizes left, top, right, and bottom. The margins are used by the layout system, and may be used by subclasses to specify the area to draw in (e.g. excluding the frame).

Changing the margins will trigger a resizeEvent().

See also contentsRect().

### void QWidget::setDisabled ( bool disable ) `[slot]`

Disables widget input events if disable is true; otherwise enables input events.

See the enabled documentation for more information.

See also isEnabledTo(), QKeyEvent, QMouseEvent, and changeEvent().

### void QWidget::setFixedHeight ( int h )

Sets both the minimum and maximum heights of the widget to h without changing the widths. Provided for convenience.

See also sizeHint(), minimumSize(), maximumSize(), and setFixedSize().

### void QWidget::setFixedSize ( const QSize & s )

Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing or shrinking.

See also setMaximumSize() and setMinimumSize().

### void QWidget::setFixedSize ( int w, int h )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the width of the widget to w and the height to h.

### void QWidget::setFixedWidth ( int w )

Sets both the minimum and maximum width of the widget to w without changing the heights. Provided for convenience.

See also sizeHint(), minimumSize(), maximumSize(), and setFixedSize().

### void QWidget::setFocus () `[slot]`

Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window.

First, a focus out event is sent to the focus widget (if any) to tell it that it is about to lose the focus. Then a focus in event is sent to this widget to tell it that it just received the focus. (Nothing happens if the focus in and focus out widgets are the same.)

setFocus() gives focus to a widget regardless of its focus policy, but does not clear any keyboard grab (see grabKeyboard()).

Be aware that if the widget is hidden, it will not accept focus.

Warning: If you call setFocus() in a function which may itself be called from focusOutEvent() or focusInEvent(), you may get an infinite recursion.

setFocusPolicy() QApplication::focusWidget() grabKeyboard() grabMouse()

See also hasFocus(), clearFocus(), focusInEvent(), and focusOutEvent().

### void QWidget::setFocusProxy ( QWidget * w )

Sets the widget's focus proxy to widget w. If w is 0, the function resets this widget to have no focus proxy.

Some widgets, such as QComboBox, can "have focus", but create a child widget to actually handle the focus. QComboBox, for example, creates a QLineEdit which handles the focus.

setFocusProxy() sets the widget which will actually get focus when "this widget" gets it. If there is a focus proxy, focusPolicy(), setFocusPolicy(), setFocus() and hasFocus() all operate on the focus proxy.

See also focusProxy().

### void QWidget::setForegroundRole ( QPalette::ColorRole role )

Sets the foreground role of the widget to role

backgroundRole(), setForegroundRole()

### void QWidget::setMask ( const QBitmap & bitmap )

Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible. If the region includes pixels outside the rect() of the widget, window system controls in that area may or may not be visible, depending on the platform.

Note that this effect can be slow if the region is particularly complex.

See `examples/tux` for an example of masking for transparency.

See also setMask() and clearMask().

### void QWidget::setMask ( const QRegion & region )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Causes only the parts of the widget which overlap region to be visible. If the region includes pixels outside the rect() of the widget, window system controls in that area may or may not be visible, depending on the platform.

Note that this effect can be slow if the region is particularly complex.

See also setMask() and clearMask().

### void QWidget::setMicroFocusHint ( int x, int y, int width, int height, bool text = true, QFont * f = 0 ) `[protected]`

When a widget gets focus, it should call setMicroFocusHint() with some appropriate position and size, x, y, width and height. This has no visual effect, it just provides hints to any system-specific input handling tools.

The text argument should be true if this is a position for text input.

In the Windows version of Qt, this method sets the system caret, which is used for user Accessibility focus handling. If text is true, it also sets the IME composition window in Far East Asian language input systems.

In the X11 version of Qt, if text is true, this method sets the XIM "spot" point for complex language input handling.

The font f is a rendering hint to the currently active input method. If f is 0 the widget's font is used.

See also microFocusHint().

### void QWidget::setParent ( QWidget * parent )

Sets the parent of the widget to parent. The widget is moved to position (0,0) in its new parent.

If the new parent widget is in a different top-level widget, the reparented widget and its children are appended to the end of the tab chain of the new parent widget, in the same internal order as before. If one of the moved widgets had keyboard focus, setParent() calls clearFocus() for that widget.

If the new parent widget is in the same top-level widget as the old parent, setting the parent doesn't change the tab order or keyboard focus.

Warning: It is extremely unlikely that you will ever need this function. If you have a widget that changes its content dynamically, it is far easier to use QWidgetStack or QWizard.

### void QWidget::setParent ( QWidget * parent, Qt::WFlags f )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This function also takes widget flags, f as an argument.

See also getWFlags().

### void QWidget::setShortcutEnabled ( int id, bool enable = true )

If enable is true, the shortcut with the given id is enabled; otherwise the shortcut is disabled.

Warning: You should not normally need to use this function since Qt's shortcut system enables/disables shortcuts automatically as widgets become hidden/visible and gain or lose focus. It is best to use QAction or QShortcut to handle shortcuts, since they are easier to use than this low-level function.

See also grabShortcut() and releaseShortcut().

### void QWidget::setStyle ( QStyle * style )

Sets the widget's GUI style to style. Ownership of the style object is not transferred.

If no style is set, the widget uses the application's style, QApplication::style() instead.

Setting a widget's style has no effect on existing or future child widgets.

Warning: This function is particularly useful for demonstration purposes, where you want to show Qt's styling capabilities. Real applications should avoid it and use one consistent GUI style instead.

See also style(), QStyle, QApplication::style(), and QApplication::setStyle().

### QStyle * QWidget::setStyle ( const QString & style )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the widget's GUI style to style using the QStyleFactory.

### void QWidget::setTabOrder ( QWidget * first, QWidget * second ) `[static]`

Moves the second widget around the ring of focus widgets so that keyboard focus moves from the first widget to the second widget when the Tab key is pressed.

Note that since the tab order of the second widget is changed, you should order a chain like this:

        setTabOrder(a, b); // a to b
        setTabOrder(b, c); // a to b to c
        setTabOrder(c, d); // a to b to c to d

not like this:

        setTabOrder(c, d); // c to d   WRONG
        setTabOrder(a, b); // a to b AND c to d
        setTabOrder(b, c); // a to b to c, but not c to d

If first or second has a focus proxy, setTabOrder() correctly substitutes the proxy.

See also setFocusPolicy() and setFocusProxy().

### void QWidget::setWFlags ( Qt::WFlags f ) `[protected]`

Sets the widget flags f.

Widget flags are a combination of Qt::WindowFlags.

See also testWFlags(), getWFlags(), and clearWFlags().

### void QWidget::setWindowRole ( const QString & role )

Sets the window's role to role. This only makes sense for top-level widgets on X11.

### void QWidget::setWindowState ( uint windowState )

Sets the window state to windowState. The window state is a OR'ed combination of Qt::WindowState: `Qt::WindowMinimized`, `Qt::WindowMaximized`, `Qt::WindowFullScreen` and `Qt::WindowActive`.

If the window is not visible (i.e. isVisible() returns false), the window state will take effect when show() is called. For visible windows, the change is immediate. For example, to toggle between full-screen and mormal mode, use the following code:

        w->setWindowState(w->windowState() ^ Qt::WindowFullScreen);

In order to restore and activate a minimized window (while preserving its maximized and/or full-screen state), use the following:

        w->setWindowState(w->windowState() & ~Qt::WindowMinimized | Qt::WindowActive);

Note: On some window systems `Qt::WindowActive` is not immediate, and may be ignored in certain cases.

See also Qt::WindowState and windowState().

### void QWidget::show () `[virtual slot]`

Shows the widget and its child widgets.

If its size or position has changed, Qt guarantees that a widget gets move and resize events just before it is shown. If the widget has not been resized yet, Qt will adjust the widget's size to a useful default using adjustSize().

You almost never have to reimplement this function. If you need to change some settings before a widget is shown, use showEvent() instead. If you need to do some delayed initialization use polishEvent().

See also showEvent(), hide(), showMinimized(), showMaximized(), showNormal(), and isVisible().

### void QWidget::showEvent ( QShowEvent * event ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive widget show events which are passed in the event parameter.

Non-spontaneous show events are sent to widgets immediately before they are shown. The spontaneous show events of top-level widgets are delivered afterwards.

See also event() and QShowEvent.

### void QWidget::showFullScreen () `[slot]`

Shows the widget in full-screen mode.

Calling this function only affects top-level widgets.

To return from full-screen mode, call showNormal().

Full-screen mode works fine under Windows, but has certain problems under X. These problems are due to limitations of the ICCCM protocol that specifies the communication between X11 clients and the window manager. ICCCM simply does not understand the concept of non-decorated full-screen windows. Therefore, the best we can do is to request a borderless window and place and resize it to fill the entire screen. Depending on the window manager, this may or may not work. The borderless window is requested using MOTIF hints, which are at least partially supported by virtually all modern window managers.

An alternative would be to bypass the window manager entirely and create a window with the Qt::WX11BypassWM flag. This has other severe problems though, like totally broken keyboard focus and very strange effects on desktop changes or when the user raises other windows.

X11 window managers that follow modern post-ICCCM specifications support full-screen mode properly.

See also showNormal(), showMaximized(), show(), hide(), and isVisible().

### void QWidget::showMaximized () `[slot]`

Shows the widget maximized.

Calling this function only affects top-level widgets.

On X11, this function may not work properly with certain window managers. See the Window Geometry documentation for an explanation.

See also setWindowState(), showNormal(), showMinimized(), show(), hide(), and isVisible().

### void QWidget::showMinimized () `[slot]`

Shows the widget minimized, as an icon.

Calling this function only affects top-level widgets.

See also showNormal(), showMaximized(), show(), hide(), isVisible(), and isMinimized().

### void QWidget::showNormal () `[slot]`

Restores the widget after it has been maximized or minimized.

Calling this function only affects top-level widgets.

See also setWindowState(), showMinimized(), showMaximized(), show(), hide(), and isVisible().

### void QWidget::stackUnder ( QWidget * w )

Places the widget under w in the parent widget's stack.

To make this work, the widget itself and w must be siblings.

See also raise() and lower().

### QStyle & QWidget::style () const

Returns the GUI style for this widget

See also QWidget::setStyle(), QApplication::setStyle(), and QApplication::style().

### void QWidget::tabletEvent ( QTabletEvent * e ) `[virtual protected]`

This event handler, for event e, can be reimplemented in a subclass to receive tablet events for the widget.

If you reimplement this handler, it is very important that you ignore() the event if you do not handle it, so that the widget's parent can interpret it.

The default implementation ignores the event.

See also QTabletEvent::ignore(), QTabletEvent::accept(), event(), and QTabletEvent.

### bool QWidget::testAttribute ( Qt::WidgetAttribute attribute ) const

Returns true if attribute attribute is set on this widget; otherwise returns false.

See also setAttribute().

### Qt::WFlags QWidget::testWFlags ( Qt::WFlags f ) const

Returns the bitwise AND of the widget flags and f.

Widget flags are a combination of Qt::WindowFlags.

If you want to test for the presence of multiple flags (or composite flags such as `Qt::WStyle_Splash`), test the return value for equality against the argument. For example:

        int flags = Qt::WStyle_Tool | Qt::WStyle_NoBorder;
        if (testWFlags(flags))
            ... // Qt::WStyle_Tool or Qt::WStyle_NoBorder or both are set
        if (testWFlags(flags) == flags)
            ... // both Qt::WStyle_Tool and Qt::WStyle_NoBorder are set

See also getWFlags(), setWFlags(), and clearWFlags().

### QWidget * QWidget::topLevelWidget () const

Returns the top-level widget for this widget, i.e. the next ancestor widget that has (or could have) a window-system frame.

If the widget is a top-level, the widget itself is returned.

Typical usage is changing the window title:

        aWidget->topLevelWidget()->setWindowTitle("New Window Title");

See also isTopLevel().

### bool QWidget::underMouse () const

Returns true if the widget is under the mouse cursor; otherwise returns false.

This value is not updated properly during drag and drop operations.

See also QEvent::Enter and QEvent::Leave.

### void QWidget::update () `[slot]`

Updates the widget unless updates are disabled or the widget is hidden.

This function does not cause an immediate repaint; instead it schedules a paint event for processing when Qt returns to the main event loop. This permits Qt to optimize for more speed and less flicker than a call to repaint() does.

Calling update() several times normally results in just one paintEvent() call.

Qt normally erases the widget's area before the paintEvent() call. If the `Qt::WRepaintNoErase` widget flag is set, the widget is responsible for painting all its pixels itself.

See also repaint(), paintEvent(), setUpdatesEnabled(), and setWFlags().

### void QWidget::update ( int x, int y, int w, int h )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This version updates a rectangle (x, y, w, h) inside the widget.

### void QWidget::update ( const QRect & r )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This version updates a rectangle r inside the widget.

### void QWidget::update ( const QRegion & rgn )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This version repaints a region rgn inside the widget.

### void QWidget::updateGeometry ()

Notifies the layout system that this widget has changed and may need to change geometry.

Call this function if the sizeHint() or sizePolicy() have changed.

For explicitly hidden widgets, updateGeometry() is a no-op. The layout system will be notified as soon as the widget is shown.

### void QWidget::updateMask () `[virtual protected]`

This function can be reimplemented in a subclass to support transparent widgets. It should be called whenever a widget changes state in a way that means that the shape mask must be recalculated.

See also setAutoMask(), updateMask(), setMask(), and clearMask().

### void QWidget::wheelEvent ( QWheelEvent * e ) `[virtual protected]`

This event handler, for event e, can be reimplemented in a subclass to receive wheel events for the widget.

If you reimplement this handler, it is very important that you ignore() the event if you do not handle it, so that the widget's parent can interpret it.

The default implementation ignores the event.

See also QWheelEvent::ignore(), QWheelEvent::accept(), event(), and QWheelEvent.

### bool QWidget::winEvent ( MSG * event ) `[virtual protected]`

This special event handler can be reimplemented in a subclass to receive native Windows events which are passed in the event parameter.

In your reimplementation of this function, if you want to stop the event being handled by Qt, return true. If you return false, this native event is passed back to Qt, which translates the event into a Qt event and sends it to the widget.

Warning: This function is not portable.

See also QApplication::winEventFilter().

### WId QWidget::winId () const

Returns the window system identifier of the widget.

Portable in principle, but if you use it you are probably about to do something non-portable. Be careful.

See also find().

### QString QWidget::windowRole () const

Returns the window's role, or an empty string.

See also windowIcon and windowTitle.

### uint QWidget::windowState () const

Returns the current window state. The window state is a OR'ed combination of Qt::WindowState: `Qt::WindowMinimized`, `Qt::WindowMaximized`, `Qt::WindowFullScreen` and `Qt::WindowActive`.

See also Qt::WindowState and setWindowState().

### bool QWidget::x11Event ( XEvent * event ) `[virtual protected]`

This special event handler can be reimplemented in a subclass to receive native X11 events which are passed in the event parameter.

In your reimplementation of this function, if you want to stop the event being handled by Qt, return true. If you return false, this native event is passed back to Qt, which translates the event into a Qt event and sends it to the widget.

Warning: This function is not portable.

See also QApplication::x11EventFilter().

### Qt::HANDLE QWidget::xftDrawHandle () const

Returns the Xft draw handle of the widget for XRender support. Use of this function is not portable. This function will return 0 if XRender support is not compiled into Qt, if the XRender extension is not supported on the X11 display, or if the handle could not be created.

### Qt::HANDLE QWidget::xftPictureHandle () const

Returns the Xft picture handle of the widget for XRender support. Use of this function is not portable. This function will return 0 if XRender support is not compiled into Qt, if the XRender extension is not supported on the X11 display, or if the handle could not be created.