![]() |
Home · All Namespaces · All Classes · Main Classes · Grouped Classes · Modules · Functions |
The QWidget class is the base class of all user interface objects. More...
#include <QWidget>
Inherits QObject and QPaintDevice.
Inherited by Phonon::EffectWidget, Phonon::SeekSlider, Phonon::VideoPlayer, Phonon::VideoWidget, Phonon::VolumeSlider, Q3ComboBox, Q3DataBrowser, Q3DataView, Q3DateTimeEdit, Q3DateTimeEditBase, Q3DockArea, Q3Header, Q3MainWindow, QAbstractButton, QAbstractSlider, QAbstractSpinBox, QAxWidget, QCalendarWidget, QComboBox, QDesignerActionEditorInterface, QDesignerFormWindowInterface, QDesignerObjectInspectorInterface, QDesignerPropertyEditorInterface, QDesignerWidgetBoxInterface, QDesktopWidget, QDialog, QDialogButtonBox, QDockWidget, QFocusFrame, QFrame, QGLWidget, QGroupBox, QHelpSearchQueryWidget, QHelpSearchResultWidget, QLineEdit, QMainWindow, QMdiSubWindow, QMenu, QMenuBar, QPrintPreviewWidget, QProgressBar, QRubberBand, QSizeGrip, QSplashScreen, QSplitterHandle, QStatusBar, QSvgWidget, QTabBar, QTabWidget, QToolBar, QWebView, QWizardPage, QWorkspace, QWSEmbedWidget, QX11EmbedContainer, and QX11EmbedWidget.
|
|
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 window. Usually, windows have a frame and a title bar, although it is also possible to create windows without such decoration using suitable window flags). In Qt, QMainWindow and the various subclasses of QDialog are the most common window types.
Every widget's constructor accepts one or two standard arguments:
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 QLabel, QPushButton, QListWidget, and QTabWidget.
A widget without a parent widget is always an independent window (top-level widget). For these widgets, setWindowTitle() and setWindowIcon() set the title bar and icon respectively.
Non-window widgets are child widgets, and are displayed within their parent widgets. Most widgets in Qt are mainly useful as child widgets. For example, it is possible to display a button as a top-level window, but most people prefer to put their buttons inside other widgets, such as QDialog.

The above diagram shows a QGroupBox widget being used to hold various child widgets in a layout provided by QGridLayout. The QLabel child widgets have been outlined to indicate their full sizes.
If you want to use a QWidget to hold child widgets you will usually want to add a layout to the parent QWidget. See Layout Classes for more information about these.
When a widgets is used as a container to group a number of child widgets, it is known as a composite widget. These can be created by constructing a widget with the required visual properties - a QFrame, for example - and adding child widgets to it, usually managed by a layout. The above diagram shows such a composite widget that was created using Qt Designer.
Composite widgets can also be created by subclassing a standard widget, such as QWidget or QFrame, and adding the necessary layout and child widgets in the constructor of the subclass. Many of the examples provided with Qt use this approach, and it is also covered in the Qt Tutorial.
Since QWidget is a subclass of QPaintDevice, subclasses can be used to display custom content that is composed using a series of painting operations with an instance of the QPainter class. This approach contrasts with the canvas-style approach used by the Graphics View Framework where items are added to a scene by the application and are rendered by the framework itself.
Each widget performs all painting operations from within its paintEvent() function. This is called whenever the widget needs to be redrawn, either as a result of some external change or when requested by the application.
The Analog Clock example shows how a simple widget can handle paint events.
When implementing a new widget, it is almost always useful to reimplement sizeHint() to provide a reasonable default size for the widget and to set the correct size policy with setSizePolicy().
By default, composite widgets which do not provide a size hint will be sized according to the space requirements of their child widgets.
The size policy lets you supply good default behavior for the layout management system, so that other widgets can contain and manage yours easily. The default size policy indicates that the size hint represents the preferred size of the widget, and this is often good enough for many widgets.
Widgets respond to events that are typically caused by user actions. Qt delivers events to widgets by calling specific event handler functions with instances of QEvent subclasses containing information about each event.
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 widget's mousePressEvent().
The Scribble example implements a wider set of events to handle mouse movement, button presses, and window resizing.
You will need to supply the behavior and content for your own widgets, but here is a brief overview of the events that are relevant to QWidget, starting with the most common ones:
Widgets that accept keyboard input need to reimplement a few more event handlers:
Some widgets will also need to reimplement some of the less common event handlers:
There are also some rather obscure events described in the QEvent::Type documentation. You need to reimplement event() directly to handle these. 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.
Events and the mechanism used to deliver them are covered in the Events and Event Filters document.
In addition to the standard widget styles for each platform, widgets can also be styled according to rules specified in a style sheet. This feature enables you to customize the appearance of specific widgets to provide visual cues to users about their purpose; for example, a button could be styled in a particular way to indicate that it performs a destructive action.
The use of widgets style sheets is described in more detail in Qt Style Sheets.
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. Additionally, it became possible for widgets to propagate their contents to children, in order to enable transparency effects, by setting the Qt::WA_ContentsPropagated widget attribute - this is now deprecated in Qt 4.1.
In Qt 4.1, the contents of parent widgets are propagated by default to each of their children. Custom widgets can be written to take advantage of this feature by only updating irregular regions (to create non-rectangular child widgets), or by using painting with colors that have less than the full alpha component. The following diagram shows how attributes and properties of a custom widget can be fine-tuned to achieve different effects.

In the above diagram, a semi-transparent rectangular child widget with an area removed is constructed and added to a parent widget (a QLabel showing a pixmap) then different properties and widget attributes are set to achieve different effects:
For rapidly updating custom widgets with simple background colors, such as real-time plotting or graphing widgets, it is better to define a suitable background color (using setBackgroundRole() with the QPalette::Window role), set the autoFillBackground property, and only implement the necessary drawing functionality in the widget's paintEvent().
For rapidly updating custom widgets that constantly paint over their entire areas with opaque content, such as video streaming widgets, it is better to set the widget's Qt::WA_OpaquePaintEvent, avoiding any unnecessary overhead associated with repainting the widget's background.
If a widget has both the Qt::WA_OpaquePaintEvent widget attribute and the autoFillBackground property set, the Qt::WA_OpaquePaintEvent attribute takes precedence. You should choose just one of these depending on your requirements.
In Qt 4.1, the contents of parent widgets are also propagated to standard Qt widgets. This can lead to some unexpected results if the parent widget is decorated in a non-standard way, as shown in the diagram below.

The scope for customizing the painting behavior of standard Qt widgets, without resorting to subclassing, is slightly less than that possible for custom widgets. Usually, the desired appearance of a standard widget can be achieved by setting its autoFillBackground property.
See also QEvent, QPainter, QGridLayout, and QBoxLayout.
This enum describes how to render the widget when calling QWidget::render().
| Constant | Value | Description |
|---|---|---|
| QWidget::DrawWindowBackground | 0x1 | If you enable this option, the widget's background is rendered into the target even if autoFillBackground is not set. By default, this option is enabled. |
| QWidget::DrawChildren | 0x2 | If you enable this option, the widget's children are rendered recursively into the target. By default, this option is enabled. |
| QWidget::IgnoreMask | 0x4 | If you enable this option, the widget's QWidget::mask() is ignored when rendering into the target. By default, this option is disabled. |
This enum was introduced in Qt 4.3.
The RenderFlags type is a typedef for QFlags<RenderFlag>. It stores an OR combination of RenderFlag values.
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 (windowType() == Qt::Desktop), 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 and drop event handler.
By default, this property is false.
Access functions:
See also Drag and Drop.
This property holds the widget's description as seen by assistive technologies.
By default, this property contains an empty string.
Access functions:
See also QAccessibleInterface::text().
This property holds the widget's name as seen by assistive technologies.
This property is used by accessible clients to identify, find, or announce the widget for accessible clients.
By default, this property contains an empty string.
Access functions:
See also QAccessibleInterface::text().
This property holds whether the widget background is filled automatically.
If enabled, this will cause Qt to fill the background of the widget before invoking the paint event. The color used is defined by the QPalette::Window color role from the widget's palette.
In addition, Windows are always filled with QPalette::Window, unless the WA_OpaquePaintEvent or WA_NoSystemBackground attributes are set.
Warning: Use this property with caution in conjunction with Qt Style Sheets. When a widget has a style sheet with a valid background or a border-image, this property is automatically disabled.
By default, this property is false.
This property was introduced in Qt 4.1.
Access functions:
See also Qt::WA_OpaquePaintEvent, Qt::WA_NoSystemBackground, and Transparency and Double Buffering.
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().
By default, for a newly-created widget, this property contains a size with zero width and height.
Access functions:
See also setSizeIncrement().
This property holds the bounding rectangle of the widget's children.
Hidden children are excluded.
By default, for a widget with no children, this property contains a rectangle with zero width and height located at the origin.
Access functions:
See also childrenRegion() and geometry().
This property holds the combined region occupied by the widget's children.
Hidden children are excluded.
By default, for a widget with no children, this property contains an empty region.
Access functions:
See also childrenRect(), geometry(), and mask().
This property holds how the widget shows a context menu.
The default value of this property is Qt::DefaultContextMenu, which means the contextMenuEvent() handler is called. Other values are Qt::NoContextMenu, Qt::PreventContextMenu, Qt::ActionsContextMenu, and Qt::CustomContextMenu. With Qt::CustomContextMenu, the signal customContextMenuRequested() is emitted.
Access functions:
See also contextMenuEvent(), customContextMenuRequested(), and actions().
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.
By default, this property contains a cursor with the Qt::ArrowCursor shape.
Access functions:
See also QApplication::setOverrideCursor().
This property holds whether the widget is enabled.
An enabled widget handles keyboard and mouse events; a disabled widget does not.
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.
By default, this property is true.
Access functions:
See also isEnabledTo(), QKeyEvent, QMouseEvent, and changeEvent().
This property holds whether this widget (or its focus proxy) has the keyboard input focus.
By default, this property is false.
Note: Obtaining the value of this property for a widget is effectively equivalent to checking whether QApplication::focusWidget() refers to the widget.
Access functions:
See also setFocus(), clearFocus(), setFocusPolicy(), and QApplication::focusWidget().
This property holds the way the widget accepts keyboard focus.
The policy is Qt::TabFocus if the widget accepts keyboard focus by tabbing, Qt::ClickFocus if the widget accepts focus by clicking, Qt::StrongFocus if it accepts both, and Qt::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(Qt::StrongFocus).
Access functions:
See also focusInEvent(), focusOutEvent(), keyPressEvent(), keyReleaseEvent(), and enabled.
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 font("Helvetica", 12, QFont::Bold);
setFont(font);
Note that when a child widget is given a different font to that of its parent widget, it will still inherit the parent's font properties unless these have been set explicitly on the child's font. For example, if the parent's font is bold, the child widget's font will be bold as well if not specified otherwise like this:
QFont font; font.setBold(false); setFont(font);
In addition to setting the font, setFont() informs all children about the change.
Note: If Qt Style Sheets are used on the same widget as setFont(), style sheets will take precedence if the settings conflict.
Access functions:
See also fontInfo() and fontMetrics().
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 windows.
By default, this property contains a value that depends on the user's platform and screen geometry.
Access functions:
See also geometry(), x(), y(), and pos().
This property holds the size of the widget including any window frame.
By default, this property contains a value that depends on the user's platform and screen geometry.
Access functions:
This property holds whether the widget is shown in full screen mode.
A widget in full screen mode occupies the whole screen area and does not display window decorations, such as a title bar.
By default, this property is false.
Access functions:
See also windowState(), minimized, and maximized.
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 window geometry.
By default, this property contains a value that depends on the user's platform and screen geometry.
Access functions:
See also frameGeometry(), rect(), move(), resize(), moveEvent(), resizeEvent(), minimumSize(), and maximumSize().
This property holds the height of the widget excluding any window frame.
See the Window Geometry documentation for an overview of window geometry.
Note: Do not use this function to find the height of a screen on a multiple screen desktop. Read this note for details.
By default, this property contains a value that depends on the user's platform and screen geometry.
Access functions:
See also geometry, width, and size.
This property holds whether this widget's window is the active window.
The active window is the window that contains the widget that has keyboard focus (The window may still have focus if it has no widgets or none of its widgets accepts keyboard focus).
When popup windows are visible, this property is true for both the active window and for the popup.
By default, this property is false.
Access functions:
See also activateWindow() and QApplication::activeWindow().
This property holds the layout direction for this widget.
By default, this property is set to Qt::LeftToRight.
Access functions:
See also QApplication::layoutDirection.
This property holds the widget's locale.
As long as no special locale has been set, this is either the parent's locale or (if this widget is a top level widget), the default locale.
If the widget displays dates or numbers, these should be formatted using the widget's locale.
This property was introduced in Qt 4.3.
Access functions:
See also QLocale and QLocale::setDefault().
This property holds whether this widget is maximized.
This property is only relevant for windows.
Note: Due to limitations on 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.
By default, this property is false.
Access functions:
See also windowState(), showMaximized(), visible, show(), hide(), showNormal(), and minimized.
This property holds the widget's maximum height in pixels.
This property corresponds to the height held by the maximumSize property.
By default, this property contains a value of 16777215.
Note: The definition of the QWIDGETSIZE_MAX macro limits the maximum size of widgets.
Access functions:
See also maximumSize and maximumWidth.
This property holds the widget's maximum size in pixels.
The widget cannot be resized to a larger size than the maximum widget size.
By default, this property contains a size in which both width and height have values of 16777215.
Note: The definition of the QWIDGETSIZE_MAX macro limits the maximum size of widgets.
Access functions:
See also maximumWidth, maximumHeight, minimumSize, and sizeIncrement.
This property holds the widget's maximum width in pixels.
This property corresponds to the width held by the maximumSize property.
By default, this property contains a value of 16777215.
Note: The definition of the QWIDGETSIZE_MAX macro limits the maximum size of widgets.
Access functions:
See also maximumSize and maximumHeight.
This property holds whether this widget is minimized (iconified).
This property is only relevant for windows.
By default, this property is false.
Access functions:
See also showMinimized(), visible, show(), hide(), showNormal(), and maximized.
This property holds the widget's minimum height in pixels.
This property corresponds to the height held by the minimumSize property.
By default, this property has a value of 0.
Access functions:
See also minimumSize and minimumWidth.
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.
The minimum size set by this function will override the minimum size defined by QLayout. In order to unset the minimum size, use a value of QSize(0, 0).
By default, this property contains a size with zero width and height.
Access functions:
See also minimumWidth, minimumHeight, maximumSize, and sizeIncrement.
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 the minimum size hint unless minimumSize() is set or the size policy is set to QSizePolicy::Ignore. If minimumSize() is set, the minimum size hint will be ignored.
Access functions:
See also QSize::isValid(), resize(), setMinimumSize(), and sizePolicy().
This property holds the widget's minimum width in pixels.
This property corresponds to the width held by the minimumSize property.
By default, this property has a value of 0.
Access functions:
See also minimumSize and minimumHeight.
This property holds whether the widget is a modal widget.
This property only makes sense for windows. A modal widget prevents widgets in all other windows from getting any input.
By default, this property is false.
Access functions:
See also isWindow(), windowModality, and QDialog.
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:
See also mouseMoveEvent().
This property holds the geometry of the widget as it will appear when shown as a normal (not maximized or full screen) top-level widget.
For child widgets this property always holds an empty rectangle.
By default, this property contains an empty rectangle.
Access functions:
See also QWidget::windowState() and QWidget::geometry.
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.
The palette's background color will only have an effect on the appearance of the widget if the autoFillBackground property is set.
There are two types of styles in Qt:
Changing this property on a widget with a pixmap based style will usually not result in a visual change on that widget. Refer to our Knowledge Base article here for more information.
Warning: Do not use this function in conjunction with Qt Style Sheets. When using style sheets, the palette of a widget can be customized using the "color", "background-color", "selection-color", "selection-background-color" and "alternate-background-color".
Access functions:
See also QApplication::palette().
This property holds the position of the widget within its parent widget.
If the widget is a window, 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.
By default, this property contains a position that refers to the origin.
Warning: Calling move() or setGeometry() inside moveEvent() can lead to infinite recursion.
See the Window Geometry documentation for an overview of window geometry.
Access functions:
See also frameGeometry, size, x(), and y().
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 window geometry.
By default, this property contains a value that depends on the user's platform and screen geometry.
Access functions:
See also size.
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().
By default, this property contains a value that depends on the user's platform and screen geometry.
Warning: Calling resize() or setGeometry() inside resizeEvent() can lead to infinite recursion.
Note: Setting the size to QSize(0, 0) will cause the widget to not appear on screen. This also applies to windows.
Access functions:
See also pos, geometry, minimumSize, maximumSize, and resizeEvent().
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:
See also QSize::isValid(), minimumSizeHint(), sizePolicy(), setMinimumSize(), and updateGeometry().
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 windows.
By default, this property contains a size with zero width and height.
Warning: The size increment has no effect under Windows, and may be disregarded by the window manager on X11.
Access functions:
See also size, minimumSize, and maximumSize.
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 scroll bars (usually subclasses of QScrollArea) tend to specify that they can use additional space, and that they can make do with less than sizeHint().
Access functions:
See also sizeHint(), QLayout, QSizePolicy, and updateGeometry().
This property holds the widget's status tip.
By default, this property contains an empty string.
Access functions:
See also toolTip and whatsThis.
This property holds the widget's style sheet.
The style sheet contains a textual description of customizations to the widget's style, as described in the Qt Style Sheets document.
Note: Qt style sheets are currently not supported for QMacStyle (the default style on Mac OS X). We plan to address this in some future release.
This property was introduced in Qt 4.2.
Access functions:
See also setStyle(), QApplication::styleSheet, and Qt Style Sheets.
This property holds the widget's tooltip.
Note that by default tooltips are only shown for widgets that are children of the active window. You can change this behavior by setting the attribute Qt::WA_AlwaysShowToolTips on the window, not on the widget with the tooltip.
If you want to control a tooltip's behavior, you can intercept the event() function and catch the QEvent::ToolTip event (e.g., if you want to customize the area for which the tooltip should be shown).
By default, this property contains an empty string.
Access functions:
See also QToolTip, statusTip, and whatsThis.
This property holds whether updates are enabled.
An updates enabled widget receives paint events and has a system background; a disabled widget does not. This also implies that calling update() and repaint() has no effect if updates are disabled.
By default, this property is true.
setUpdatesEnabled() is normally used to disable updates for a short period of time, for instance to avoid screen flicker during large changes. In Qt, widgets normally do not generate screen flicker, but on X11 the server might erase regions on the screen when widgets get hidden before they can be replaced by other widgets. Disabling updates solves this.
Example:
setUpdatesEnabled(false); bigVisualChanges(); setUpdatesEnabled(true);
Disabling a widget implicitly disables all its children. Enabling respectively enables all child widgets unless they have been explicitly disabled. Re-enabling updates implicitly calls update() on the widget.
Access functions:
See also paintEvent().
This property holds whether the widget is visible.
Calling setVisible(true) or show() sets the widget to visible status if all its parent widgets up to the window are visible. If an ancestor is not visible, the widget won't become visible until all its ancestors are shown. 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().
Calling setVisible(false) or 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 windows 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.
You almost never have to reimplement the setVisible() 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 the Polish event delivered to the event() function.
Access functions:
See also show(), hide(), isHidden(), isVisibleTo(), isMinimized(), showEvent(), and hideEvent().
This property holds the widget's What's This help text.
By default, this property contains an empty string.
Access functions:
See also QWhatsThis, QWidget::toolTip, and QWidget::statusTip.
This property holds the width of the widget excluding any window frame.
See the Window Geometry documentation for an overview of window geometry.
Note: Do not use this function to find the width of a screen on a multiple screen desktop. Read this note for details.
By default, this property contains a value that depends on the user's platform and screen geometry.
Access functions:
See also geometry, height, and size.
This property holds the file path associated with a widget.
This property only makes sense for windows. It associates a file path with a window. If you set the file path, but have not set the window title, Qt sets the window title to contain a string created using the following components.
On Mac OS X:
On Windows and X11:
If the window title is set at any point, then the window title takes precedence and will be shown instead of the file path string.
Additionally, on Mac OS X, this has an added benefit that it sets the proxy icon for the window, assuming that the file path exists.
If no file path is set, this property contains an empty string.
By default, this property contains an empty string.
This property was introduced in Qt 4.4.
Access functions:
See also windowTitle and windowIcon.
Window flags are a combination of a type (e.g. Qt::Dialog) and zero or more hints to the window system (e.g. Qt::FramelessWindowHint).
If the widget had type Qt::Widget or Qt::SubWindow and becomes a window (Qt::Window, Qt::Dialog, etc.), it is put at position (0, 0) on the desktop. If the widget is a window and becomes a Qt::Widget or Qt::SubWindow, it is put at position (0, 0) relative to its parent widget.
Note: This function calls setParent() when changing the flags for a window, causing the widget to be hidden. You must call show() to make the widget visible again..
Access functions:
See also windowType() and Window Flags Example.
This property holds the widget's icon.
This property only makes sense for windows. If no icon has been set, windowIcon() returns the application icon (QApplication::windowIcon()).
Access functions:
See also windowIconText and windowTitle.
This property holds the widget's icon text.
This property only makes sense for windows. If no icon text has been set, this functions returns an empty string.
Access functions:
See also windowIcon and windowTitle.
This property holds which windows are blocked by the modal widget.
This property only makes sense for windows. A modal widget prevents widgets in other windows from getting input. The value of this property controls which windows are blocked when the widget is visible. Changing this property while the window is visible has no effect; you must hide() the widget first, then show() it again.
By default, this property is Qt::NonModal.
This property was introduced in Qt 4.1.
Access functions:
See also isWindow(), QWidget::modal, and QDialog.
This property holds whether the document shown in the window has unsaved changes.
A modified window is a window whose content has changed but has not been saved to disk. This flag will have different effects varied by the platform. On Mac OS X the close button will have a modified look; on other platforms, the window title will have an '*' (asterisk).
The window title must contain a "[*]" placeholder, which indicates where the '*' should appear. Normally, it should appear right after the file name (e.g., "document1.txt[*] - Text Editor"). If the window isn't modified, the placeholder is simply removed.
Note that if a widget is set as modified, all its ancestors will also be set as modified. However, if you call setWindowModified(false) on a widget, this will not propagate to its parent because other children of the parent might have been modified.
Access functions:
See also windowTitle, Application Example, SDI Example, and MDI Example.
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 available on Embedded Linux, Mac OS X, X11 platforms that support the Composite extension, and Windows 2000 and later.
This feature is not available on Windows CE.
Note that under X11 you need to have a composite manager running, and the X11 specific _NET_WM_WINDOW_OPACITY atom needs to be supported by the window manager you are using.
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:
See also setMask().
This property holds the window title (caption).
This property only makes sense for top-level widgets, such as windows and dialogs. If no caption has been set, the title is based of the windowFilePath. If neither of these is set, then the title is an empty string.
If you use the windowModified mechanism, the window title must contain a "[*]" placeholder, which indicates where the '*' should appear. Normally, it should appear right after the file name (e.g., "document1.txt[*] - Text Editor"). If the windowModified property is false (the default), the placeholder is simply removed.
Access functions:
See also windowIcon, windowIconText, windowModified, and windowFilePath.
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 window geometry.
By default, this property has a value of 0.
Access functions:
See also frameGeometry, y, and pos.
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 window geometry.
By default, this property has a value of 0.
Access functions:
See also frameGeometry, x, and pos.
Constructs a widget which is a child of parent, with widget flags set to f.
If parent is 0, the new widget becomes a 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 frame of a window (i.e. parent must be 0). To customize the frame, use a value composed from the bitwise OR of any of the window flags.
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.
See also windowFlags.
Destroys the widget.
All this widget's children are deleted first. The application exits if this widget is the main widget.
This event handler is called with the given event whenever the widget's actions are changed.
See also addAction(), insertAction(), removeAction(), actions(), and QActionEvent.
Returns the (possibly empty) list of this widget's actions.
See also contextMenuPolicy, insertAction(), and removeAction().
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 activateWindow() 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 change the color of the taskbar entry to indicate that the window has ch