| Home · 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 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, QLineEdit, QMainWindow, QMenu, QMenuBar, QProgressBar, QRubberBand, QSizeGrip, QSplashScreen, QSplitterHandle, QStatusBar, QSvgWidget, QTabBar, QTabWidget, QToolBar, 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 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::(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&Drop event handler.
Access functions:
This property holds the widget's description as seen by assistive technologies.
Access functions:
See also QAccessibleInterface::text().
This property holds the widget's name as seen by assistive technologies.
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 using the widget's background role before invoking the paint event. The background role is defined by the widget's palette.
In addition, Windows are always filled with QPalette::Window, unless the WA_OpaquePaintEvent or WA_NoSystemBackground attributes are set.
This property was introduced in Qt 4.1.
Access functions:
See also Qt::WA_OpaquePaintEvent and Qt::WA_NoSystemBackground.
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:
See also setSizeIncrement().
This property holds the bounding rectangle of the widget's children.
Hidden children are excluded.
Access functions:
See also childrenRegion() and geometry().
This property holds the combined region occupied by the widget's children.
Hidden children are excluded.
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.
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.
Access functions:
See also isEnabledTo(), QKeyEvent, QMouseEvent, and changeEvent().
This property holds whether this widget (or its focus proxy) has the keyboard input focus.
Effectively equivalent to QApplication::focusWidget() == this.
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.
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.
Access functions:
See also geometry(), x(), y(), and pos().
This property holds the size of the widget including any window frame.
Access functions:
This property holds whether the widget is full screen.
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.
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.
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.
When popup windows are visible, this property is true for both the active window and for the popup.
Access functions:
See also activateWindow() and QApplication::activeWindow().
This property holds the layout direction for this widget.
Access functions:
See also QApplication::layoutDirection.
This property holds whether this widget is maximized.
This property is only relevant for windows.
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:
See also windowState(), showMaximized(), visible, show(), hide(), showNormal(), and minimized.
This property holds the widget's maximum height.
This property corresponds to maximumSize().height(). It is limited by the QWIDGETSIZE_MAX macro, i.e. the largest allowed height is 16777215.
Access functions:
See also maximumSize and maximumWidth.
This property holds the widget's maximum size.
The widget cannot be resized to a larger size than the maximum widget size.
The property is limited by the QWIDGETSIZE_MAX macro, i.e. the largest allowed size is QSize(16777215, 16777215).
Access functions:
See also maximumWidth, maximumHeight, minimumSize, and sizeIncrement.
This property holds the widget's maximum width.
This property corresponds to maximumSize().width(). It is limited by the QWIDGETSIZE_MAX macro, i.e. the largest allowed width is 16777215.
Access functions:
See also maximumSize and maximumHeight.
This property holds whether this widget is minimized (iconified).
This property is only relevant for windows.
Access functions:
See also showMinimized(), visible, show(), hide(), showNormal(), and maximized.
This property holds the widget's minimum height.
This property corresponds to minimumSize().height().
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.
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.
This property corresponds to minimumSize().width().
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.
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 fullscreen) toplevel widget.
For child widgets this property always holds an empty rect.
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.
Note: The palette's background color will only have an effect on the appearance of the widget if the autoFillBackground property is set.
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.
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.
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(). For windows, the minimum size is always at least QSize(1, 1), and it might be larger, depending on the window manager.
Warning: Calling resize() or setGeometry() inside resizeEvent() can lead to infinite recursion.
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.
Warning: The size increment has no effect under Windows, and may be disregarded by the window manager on X.
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 scrollbars (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.
Access functions:
See also toolTip and whatsThis.
This property holds the widget's style sheet.
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 active windows. You can change this behavior by setting the attribute Qt::WA_AlwaysShowToolTips to true.
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).
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.
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.
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.
Access functions:
See also geometry, height, and size.
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.
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.
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 Mac OS X, X11 platforms that support the Composite extension, and Windows 2000 and later.
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 windows. If no caption has been set, 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, and windowModified.
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.
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.
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 changed in some way. This is because Microsoft do not allow an application to interrupt what the user is currently doing in another application.
See also isActiveWindow(), window(), and show().
Appends the action action to this widget's list of actions.
All QWidgets have a 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.
A QWidget should only have one of each action.
See also removeAction(), insertAction(), actions(), and QMenu.
Appends the actions actions to this widget's list of actions.
See also removeAction(), QMenu, and addAction().
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 that covers all child widgets (the union of all child widget rectangles). For top-level widgets, the screen size is also taken into account.
See also sizeHint() and childrenRect().
Returns the background role of the widget.
The background role defines the brush from the widget's palette that is used to render the background.
If no explicit background role is set, the widget inherts its parent widget's background role.
See also setBackgroundRole() and foregroundRole().
This event handler can be reimplemented to handle state changes.
The state being changed in this event can be retrieved through event event.
Change events include: QEvent::ToolBarChange, QEvent::ActivationChange, QEvent::EnabledChange, QEvent::FontChange, QEvent::StyleChange, QEvent::PaletteChange, QEvent::WindowTitleChange, QEvent::IconTextChange, QEcvent::ModifiedChange, QEvent::MouseTrackingChange, QEvent::ParentChange, QEvent::WindowStateChange, QEvent::LanguageChange, QEvent::LocaleChange, QEvent::LayoutDirectionChange.
Returns the visible child widget at the position (x, y) in the widget's coordinate system. If there is no visible child widget at the specified position, the function returns 0.
This is an overloaded member function, provided for convenience.
Returns the visible child widget at point p in the widget's own coordinate system.
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().
Removes any mask set by setMask().
See also setMask().
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 primary window (i.e. window with no parent) with the Qt::WA_QuitOnClose attribute set is closed. By default this attribute is set for all widgets except transient windows such as splash screens, tool windows, and popup menus.
This event handler, for event event, can be reimplemented in a subclass to receive widget close events.
See also event(), hide(), close(), QCloseEvent, and Application Example.
Returns the area inside the widget's margins.
See also setContentsMargins() and getContentsMargins().
This event handler, for event event, can be reimplemented in a subclass to receive widget context menu events.
The handler is called when the widget's contextMenuPolicy is Qt::DefaultContextMenu.
The default implementation ignores the context event. See the QContextMenuEvent documentation for more details.
See also event(), QContextMenuEvent, and customContextMenuRequested().
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.
This signal is emitted when the widget's contextMenuPolicy is Qt::CustomContextMenu, and the user has requested a context menu on the widget. The position pos is the position of the context menu event that the widget receives. Normally this is in widget coordinates. The exception to this rule is QAbstractScrollArea and its subclasses that map the context menu event to coordinates of the viewport() .
See also mapToGlobal(), QMenu, and contextMenuPolicy.
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.
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.
If the event is ignored, the widget won't receive any drag move events.
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.
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.
This event handler is called if a drag is in progress, and when any