QWidget Class Reference |
enum | RenderFlag { DrawWindowBackground, DrawChildren, IgnoreMask } |
flags | RenderFlags |
|
|
QWidget ( QWidget * parent = 0, Qt::WindowFlags f = 0 ) | |
~QWidget () | |
bool | acceptDrops () const |
QString | accessibleDescription () const |
QString | accessibleName () const |
QList<QAction *> | actions () const |
void | activateWindow () |
void | addAction ( QAction * action ) |
void | addActions ( QList<QAction *> actions ) |
void | adjustSize () |
bool | autoFillBackground () const |
QPalette::ColorRole | backgroundRole () const |
QSize | baseSize () const |
QWidget * | childAt ( int x, int y ) const |
QWidget * | childAt ( const QPoint & p ) const |
QRect | childrenRect () const |
QRegion | childrenRegion () const |
void | clearFocus () |
void | clearMask () |
QMargins | contentsMargins () const |
QRect | contentsRect () const |
Qt::ContextMenuPolicy | contextMenuPolicy () const |
QCursor | cursor () const |
WId | effectiveWinId () const |
void | ensurePolished () const |
Qt::FocusPolicy | focusPolicy () const |
QWidget * | focusProxy () const |
QWidget * | focusWidget () const |
const QFont & | font () const |
QFontInfo | fontInfo () const |
QFontMetrics | fontMetrics () const |
QPalette::ColorRole | foregroundRole () const |
QRect | frameGeometry () const |
QSize | frameSize () const |
const QRect & | geometry () const |
void | getContentsMargins ( int * left, int * top, int * right, int * bottom ) const |
void | grabGesture ( Qt::GestureType gesture, Qt::GestureFlags flags = Qt::GestureFlags() ) |
void | grabKeyboard () |
void | grabMouse () |
void | grabMouse ( const QCursor & cursor ) |
int | grabShortcut ( const QKeySequence & key, Qt::ShortcutContext context = Qt::WindowShortcut ) |
QGraphicsEffect * | graphicsEffect () const |
QGraphicsProxyWidget * | graphicsProxyWidget () const |
bool | hasEditFocus () const |
bool | hasFocus () const |
bool | hasMouseTracking () const |
int | height () const |
virtual int | heightForWidth ( int w ) const |
QInputContext * | inputContext () |
Qt::InputMethodHints | inputMethodHints () const |
virtual QVariant | inputMethodQuery ( Qt::InputMethodQuery query ) const |
void | insertAction ( QAction * before, QAction * action ) |
void | insertActions ( QAction * before, QList<QAction *> actions ) |
bool | isActiveWindow () const |
bool | isAncestorOf ( const QWidget * child ) const |
bool | isEnabled () const |
bool | isEnabledTo ( QWidget * ancestor ) const |
bool | isFullScreen () const |
bool | isHidden () const |
bool | isMaximized () const |
bool | isMinimized () const |
bool | isModal () const |
bool | isVisible () const |
bool | isVisibleTo ( QWidget * ancestor ) const |
bool | isWindow () const |
bool | isWindowModified () const |
QLayout * | layout () const |
Qt::LayoutDirection | layoutDirection () const |
QLocale | locale () const |
Qt::HANDLE | macCGHandle () const |
Qt::HANDLE | macQDHandle () 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 |
int | maximumHeight () const |
QSize | maximumSize () const |
int | maximumWidth () const |
int | minimumHeight () const |
QSize | minimumSize () const |
virtual QSize | minimumSizeHint () const |
int | minimumWidth () const |
void | move ( const QPoint & ) |
void | move ( int x, int y ) |
QWidget * | nativeParentWidget () const |
QWidget * | nextInFocusChain () const |
QRect | normalGeometry () const |
void | overrideWindowFlags ( Qt::WindowFlags flags ) |
const QPalette & | palette () const |
QWidget * | parentWidget () const |
QPoint | pos () const |
QWidget * | previousInFocusChain () const |
QRect | rect () const |
void | releaseKeyboard () |
void | releaseMouse () |
void | releaseShortcut ( int id ) |
void | removeAction ( QAction * action ) |
void | render ( QPaintDevice * target, const QPoint & targetOffset = QPoint(), const QRegion & sourceRegion = QRegion(), RenderFlags renderFlags = RenderFlags( DrawWindowBackground | DrawChildren ) ) |
void | render ( QPainter * painter, const QPoint & targetOffset = QPoint(), const QRegion & sourceRegion = QRegion(), RenderFlags renderFlags = RenderFlags( DrawWindowBackground | DrawChildren ) ) |
void | repaint ( int x, int y, int w, int h ) |
void | repaint ( const QRect & rect ) |
void | repaint ( const QRegion & rgn ) |
void | resize ( const QSize & ) |
void | resize ( int w, int h ) |
bool | restoreGeometry ( const QByteArray & geometry ) |
QByteArray | saveGeometry () const |
void | scroll ( int dx, int dy ) |
void | scroll ( int dx, int dy, const QRect & r ) |
void | setAcceptDrops ( bool on ) |
void | setAccessibleDescription ( const QString & description ) |
void | setAccessibleName ( const QString & name ) |
void | setAttribute ( Qt::WidgetAttribute attribute, bool on = true ) |
void | setAutoFillBackground ( bool enabled ) |
void | setBackgroundRole ( QPalette::ColorRole role ) |
void | setBaseSize ( const QSize & ) |
void | setBaseSize ( int basew, int baseh ) |
void | setContentsMargins ( int left, int top, int right, int bottom ) |
void | setContentsMargins ( const QMargins & margins ) |
void | setContextMenuPolicy ( Qt::ContextMenuPolicy policy ) |
void | setCursor ( const QCursor & ) |
void | setEditFocus ( bool enable ) |
void | setFixedHeight ( int h ) |
void | setFixedSize ( const QSize & s ) |
void | setFixedSize ( int w, int h ) |
void | setFixedWidth ( int w ) |
void | setFocus ( Qt::FocusReason reason ) |
void | setFocusPolicy ( Qt::FocusPolicy policy ) |
void | setFocusProxy ( QWidget * w ) |
void | setFont ( const QFont & ) |
void | setForegroundRole ( QPalette::ColorRole role ) |
void | setGeometry ( const QRect & ) |
void | setGeometry ( int x, int y, int w, int h ) |
void | setGraphicsEffect ( QGraphicsEffect * effect ) |
void | setInputContext ( QInputContext * context ) |
void | setInputMethodHints ( Qt::InputMethodHints hints ) |
void | setLayout ( QLayout * layout ) |
void | setLayoutDirection ( Qt::LayoutDirection direction ) |
void | setLocale ( const QLocale & locale ) |
void | setMask ( const QBitmap & bitmap ) |
void | setMask ( const QRegion & region ) |
void | setMaximumHeight ( int maxh ) |
void | setMaximumSize ( const QSize & ) |
void | setMaximumSize ( int maxw, int maxh ) |
void | setMaximumWidth ( int maxw ) |
void | setMinimumHeight ( int minh ) |
void | setMinimumSize ( const QSize & ) |
void | setMinimumSize ( int minw, int minh ) |
void | setMinimumWidth ( int minw ) |
void | setMouseTracking ( bool enable ) |
void | setPalette ( const QPalette & ) |
void | setParent ( QWidget * parent ) |
void | setParent ( QWidget * parent, Qt::WindowFlags f ) |
void | setShortcutAutoRepeat ( int id, bool enable = true ) |
void | setShortcutEnabled ( int id, bool enable = true ) |
void | setSizeIncrement ( const QSize & ) |
void | setSizeIncrement ( int w, int h ) |
void | setSizePolicy ( QSizePolicy ) |
void | setSizePolicy ( QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical ) |
void | setStatusTip ( const QString & ) |
void | setStyle ( QStyle * style ) |
void | setToolTip ( const QString & ) |
void | setUpdatesEnabled ( bool enable ) |
void | setWhatsThis ( const QString & ) |
void | setWindowFilePath ( const QString & filePath ) |
void | setWindowFlags ( Qt::WindowFlags type ) |
void | setWindowIcon ( const QIcon & icon ) |
void | setWindowIconText ( const QString & ) |
void | setWindowModality ( Qt::WindowModality windowModality ) |
void | setWindowOpacity ( qreal level ) |
void | setWindowRole ( const QString & role ) |
void | setWindowState ( Qt::WindowStates windowState ) |
void | setWindowSurface ( QWindowSurface * surface ) (preliminary) |
void | setupUi ( QWidget * widget ) |
QSize | size () const |
virtual QSize | sizeHint () const |
QSize | sizeIncrement () const |
QSizePolicy | sizePolicy () const |
void | stackUnder ( QWidget * w ) |
QString | statusTip () const |
QStyle * | style () const |
QString | styleSheet () const |
bool | testAttribute ( Qt::WidgetAttribute attribute ) const |
QString | toolTip () const |
bool | underMouse () const |
void | ungrabGesture ( Qt::GestureType gesture ) |
void | unsetCursor () |
void | unsetLayoutDirection () |
void | unsetLocale () |
void | update ( int x, int y, int w, int h ) |
void | update ( const QRect & rect ) |
void | update ( const QRegion & rgn ) |
void | updateGeometry () |
bool | updatesEnabled () const |
QRegion | visibleRegion () const |
QString | whatsThis () const |
int | width () const |
WId | winId () const |
QWidget * | window () const |
QString | windowFilePath () const |
Qt::WindowFlags | windowFlags () const |
QIcon | windowIcon () const |
QString | windowIconText () const |
Qt::WindowModality | windowModality () const |
qreal | windowOpacity () const |
QString | windowRole () const |
Qt::WindowStates | windowState () const |
QWindowSurface * | windowSurface () const (preliminary) |
QString | windowTitle () const |
Qt::WindowType | windowType () const |
int | x () const |
const QX11Info & | x11Info () const |
Qt::HANDLE | x11PictureHandle () const |
int | y () const |
virtual HDC | getDC () const |
virtual QPaintEngine * | paintEngine () const |
virtual void | releaseDC ( HDC hdc ) const |
bool | close () |
void | hide () |
void | lower () |
void | raise () |
void | repaint () |
void | setDisabled ( bool disable ) |
void | setEnabled ( bool ) |
void | setFocus () |
void | setHidden ( bool hidden ) |
void | setStyleSheet ( const QString & styleSheet ) |
virtual void | setVisible ( bool visible ) |
void | setWindowModified ( bool ) |
void | setWindowTitle ( const QString & ) |
void | show () |
void | showFullScreen () |
void | showMaximized () |
void | showMinimized () |
void | showNormal () |
void | update () |
void | customContextMenuRequested ( const QPoint & pos ) |
QWidget * | find ( WId id ) |
QWidget * | keyboardGrabber () |
QWidget * | mouseGrabber () |
void | setTabOrder ( QWidget * first, QWidget * second ) |
virtual void | actionEvent ( QActionEvent * event ) |
virtual void | changeEvent ( QEvent * event ) |
virtual void | closeEvent ( QCloseEvent * event ) |
virtual void | contextMenuEvent ( QContextMenuEvent * event ) |
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 void | focusInEvent ( QFocusEvent * event ) |
bool | focusNextChild () |
virtual bool | focusNextPrevChild ( bool next ) |
virtual void | focusOutEvent ( QFocusEvent * event ) |
bool | focusPreviousChild () |
virtual void | hideEvent ( QHideEvent * event ) |
virtual void | inputMethodEvent ( QInputMethodEvent * event ) |
virtual void | keyPressEvent ( QKeyEvent * event ) |
virtual void | keyReleaseEvent ( QKeyEvent * event ) |
virtual void | leaveEvent ( QEvent * event ) |
virtual bool | macEvent ( EventHandlerCallRef caller, EventRef event ) |
virtual void | mouseDoubleClickEvent ( QMouseEvent * event ) |
virtual void | mouseMoveEvent ( QMouseEvent * event ) |
virtual void | mousePressEvent ( QMouseEvent * event ) |
virtual void | mouseReleaseEvent ( QMouseEvent * event ) |
virtual void | moveEvent ( QMoveEvent * event ) |
virtual void | paintEvent ( QPaintEvent * event ) |
virtual bool | qwsEvent ( QWSEvent * event ) |
virtual void | resizeEvent ( QResizeEvent * event ) |
virtual void | showEvent ( QShowEvent * event ) |
virtual void | tabletEvent ( QTabletEvent * event ) |
virtual void | wheelEvent ( QWheelEvent * event ) |
virtual bool | winEvent ( MSG * message, long * result ) |
virtual bool | x11Event ( XEvent * event ) |
virtual bool | event ( QEvent * event ) |
virtual int | metric ( PaintDeviceMetric m ) const |
void | updateMicroFocus () |
typedef | QWidgetList |
typedef | WId |
QWIDGETSIZE_MAX |
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 is not 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, 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 diagram above 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 Management for more information.
When a widget 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 Tutorials.
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.
Note: The size of top-level widgets are constrained to 2/3 of the desktop's height and width. You can resize() the widget manually if these bounds are inadequate.
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:
You may be required to also reimplement some of the less common event handlers:
There are also some rather obscure events described in the documentation for QEvent::Type. To handle these events, you need to reimplement event() directly.
The default implementation of event() handles Tab and Shift+Tab (to move the keyboard focus), and passes on most of the 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 widget style sheets is described in more detail in the Qt Style Sheets document.
Since Qt 4.0, QWidget automatically double-buffers its painting, so there is no need to write double-buffering code in paintEvent() to avoid flicker.
Since Qt 4.1, the Qt::WA_ContentsPropagated widget attribute has been deprecated. Instead, the contents of parent widgets are propagated by default to each of their children as long as Qt::WA_PaintOnScreen is not set. Custom widgets can be written to take advantage of this feature by updating irregular regions (to create non-rectangular child widgets), or painting with colors that have less than 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:
To rapidly update 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().
To rapidly update custom widgets that constantly paint over their entire areas with opaque content, e.g., 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. Depending on your requirements, you should choose either one of them.
Since 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.
Since Qt 4.5, it has been possible to create windows with translucent regions on window systems that support compositing.
To enable this feature in a top-level widget, set its Qt::WA_TranslucentBackground attribute with setAttribute() and ensure that its background is painted with non-opaque colors in the regions you want to be partially transparent.
Platform notes:
Introduced in Qt 4.4, alien widgets are widgets unknown to the windowing system. They do not have a native window handle associated with them. This feature significantly speeds up widget painting, resizing, and removes flicker.
Should you require the old behavior with native windows, you can choose one of the following options:
Since Qt 4.6, Softkeys are usually physical keys on a device that have a corresponding label or other visual representation on the screen that is generally located next to its physical counterpart. They are most often found on mobile phone platforms. In modern touch based user interfaces it is also possible to have softkeys that do not correspond to any physical keys. Softkeys differ from other onscreen labels in that they are contextual.
In Qt, contextual softkeys are added to a widget by calling addAction() and passing a QAction with a softkey role set on it. When the widget containing the softkey actions has focus, its softkeys should appear in the user interface. Softkeys are discovered by traversing the widget hierarchy so it is possible to define a single set of softkeys that are present at all times by calling addAction() for a given top level widget.
On some platforms, this concept overlaps with QMenuBar such that if no other softkeys are found and the top level widget is a QMainWindow containing a QMenuBar, the menubar actions may appear on one of the softkeys.
Note: Currently softkeys are only supported on the Symbian Platform.
See also QEvent, QPainter, QGridLayout, QBoxLayout, addAction(), QAction, and QMenuBar.
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:
bool | acceptDrops () const |
void | setAcceptDrops ( bool on ) |
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:
QString | accessibleDescription () const |
void | setAccessibleDescription ( const QString & description ) |
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:
QString | accessibleName () const |
void | setAccessibleName ( const QString & name ) |
See also QAccessibleInterface::text().
This property holds whether the widget background is filled automatically.
If enabled, this property 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.
This property cannot be turned off (i.e., set to false) if a widget's parent has a static gradient for its background.
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:
bool | autoFillBackground () const |
void | setAutoFillBackground ( bool enabled ) |
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:
QSize | baseSize () const |
void | setBaseSize ( const QSize & ) |
void | setBaseSize ( int basew, int baseh ) |
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:
QRect | childrenRect () const |
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:
QRegion | childrenRegion () const |
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:
Qt::ContextMenuPolicy | contextMenuPolicy () const |
void | setContextMenuPolicy ( Qt::ContextMenuPolicy policy ) |
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.
Some underlying window implementations will reset the cursor if it leaves a widget even if the mouse is grabbed. If you want to have a cursor set for all widgets, even when outside the window, consider QApplication::setOverrideCursor().
Access functions:
QCursor | cursor () const |
void | setCursor ( const QCursor & ) |
void | unsetCursor () |
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:
bool | isEnabled () const |
void | setEnabled ( bool ) |
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:
bool | hasFocus () const |
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).
If the widget has a focus proxy, then the focus policy will be propagated to it.
Access functions:
Qt::FocusPolicy | focusPolicy () const |
void | setFocusPolicy ( Qt::FocusPolicy policy ) |
See also focusInEvent(), focusOutEvent(), keyPressEvent(), keyReleaseEvent(), and enabled.
This property holds the font currently set for the widget.
This property describes the widget's requested font. The font is used by the widget's style when rendering standard components, and is available as a means to ensure that custom widgets can maintain consistency with the native platform's look and feel. It's common that different platforms, or different styles, define different fonts for an application.
When you assign a new font to a widget, the properties from this font are combined with the widget's default font to form the widget's final font. You can call fontInfo() to get a copy of the widget's final font. The final font is also used to initialize QPainter's font.
The default depends on the system environment. QApplication maintains a system/theme font which serves as a default for all widgets. There may also be special font defaults for certain types of widgets. You can also define default fonts for widgets yourself by passing a custom font and the name of a widget to QApplication::setFont(). Finally, the font is matched against Qt's font database to find the best match.
QWidget propagates explicit font properties from parent to child. If you change a specific property on a font and assign that font to a widget, that property will propagate to all the widget's children, overriding any system defaults for that property. Note that fonts by default don't propagate to windows (see isWindow()) unless the Qt::WA_WindowPropagation attribute is enabled.
QWidget's font propagation is similar to its palette propagation.
The current style, which is used to render the content of all standard Qt widgets, is free to choose to use the widget font, or in some cases, to ignore it (partially, or completely). In particular, certain styles like GTK style, Mac style, Windows XP, and Vista style, apply special modifications to the widget font to match the platform's native look and feel. Because of this, assigning properties to a widget's font is not guaranteed to change the appearance of the widget. Instead, you may choose to apply a styleSheet.
Note: If Qt Style Sheets are used on the same widget as setFont(), style sheets will take precedence if the settings conflict.
Access functions:
const QFont & | font () const |
void | setFont ( const QFont & ) |
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:
QRect | frameGeometry () const |
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:
QSize | frameSize () const |
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:
bool | isFullScreen () const |
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 geometry issues with windows.
By default, this property contains a value that depends on the user's platform and screen 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().
This property holds the height of the widget excluding any window frame.
See the Window Geometry documentation for an overview of geometry issues with windows.
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:
int | height () const |
See also geometry, width, and size.
This property holds what input method specific hints the widget has.
This is only relevant for input widgets. It is used by the input method to retrieve hints as to how the input method should operate. For example, if the Qt::ImhFormattedNumbersOnly flag is set, the input method may change its visual components to reflect that only numbers can be entered.
Note: The flags are only hints, so the particular input method implementation is free to ignore them. If you want to be sure that a certain type of characters are entered, you should also set a QValidator on the widget.
The default value is Qt::ImhNone.
This property was introduced in Qt 4.6.
Access functions:
Qt::InputMethodHints | inputMethodHints () const |
void | setInputMethodHints ( Qt::InputMethodHints hints ) |
See also inputMethodQuery() and QInputContext.
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:
bool | isActiveWindow () const |
See also activateWindow() and QApplication::activeWindow().
This property holds the layout direction for this widget.
By default, this property is set to Qt::LeftToRight.
When the layout direction is set on a widget, it will propagate to the widget's children, but not to a child that is a window and not to a child for which setLayoutDirection() has been explicitly called. Also, child widgets added after setLayoutDirection() has been called for the parent do not inherit the parent's layout direction.
Access functions:
Qt::LayoutDirection | layoutDirection () const |
void | setLayoutDirection ( Qt::LayoutDirection direction ) |
void | unsetLayoutDirection () |
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:
QLocale | locale () const |
void | setLocale ( const QLocale & locale ) |
void | unsetLocale () |
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:
bool | isMaximized () const |
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:
int | maximumHeight () const |
void | setMaximumHeight ( int maxh ) |
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:
QSize | maximumSize () const |
void | setMaximumSize ( const QSize & ) |
void | setMaximumSize ( int maxw, int maxh ) |
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:
int | maximumWidth () const |
void | setMaximumWidth ( int maxw ) |
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:
bool | isMinimized () const |
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:
int | minimumHeight () const |
void | setMinimumHeight ( int minh ) |
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:
QSize | minimumSize () const |
void | setMinimumSize ( const QSize & ) |
void | setMinimumSize ( int minw, int minh ) |
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:
virtual QSize | minimumSizeHint () const |
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:
int | minimumWidth () const |
void | setMinimumWidth ( int minw ) |
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:
bool | isModal () const |
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:
bool | hasMouseTracking () const |
void | setMouseTracking ( bool enable ) |
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:
QRect | normalGeometry () const |
See also QWidget::windowState() and QWidget::geometry.
This property holds the widget's palette.
This property describes the widget's palette. The palette is used by the widget's style when rendering standard components, and is available as a means to ensure that custom widgets can maintain consistency with the native platform's look and feel. It's common that different platforms, or different styles, have different palettes.
When you assign a new palette to a widget, the color roles from this palette are combined with the widget's default palette to form the widget's final palette. The palette entry for the widget's background role is used to fill the widget's background (see QWidget::autoFillBackground), and the foreground role initializes QPainter's pen.
The default depends on the system environment. QApplication maintains a system/theme palette which serves as a default for all widgets. There may also be special palette defaults for certain types of widgets (e.g., on Windows XP and Vista, all classes that derive from QMenuBar have a special default palette). You can also define default palettes for widgets yourself by passing a custom palette and the name of a widget to QApplication::setPalette(). Finally, the style always has the option of polishing the palette as it's assigned (see QStyle::polish()).
QWidget propagates explicit palette roles from parent to child. If you assign a brush or color to a specific role on a palette and assign that palette to a widget, that role will propagate to all the widget's children, overriding any system defaults for that role. Note that palettes by default don't propagate to windows (see isWindow()) unless the Qt::WA_WindowPropagation attribute is enabled.
QWidget's palette propagation is similar to its font propagation.
The current style, which is used to render the content of all standard Qt widgets, is free to choose colors and brushes from the widget palette, or in some cases, to ignore the palette (partially, or completely). In particular, certain styles like GTK style, Mac style, Windows XP, and Vista style, depend on third party APIs to render the content of widgets, and these styles typically do not follow the palette. Because of this, assigning roles to a widget's palette is not guaranteed to change the appearance of the widget. Instead, you may choose to apply a styleSheet. You can 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:
const QPalette & | palette () const |
void | setPalette ( const QPalette & ) |
See also QApplication::palette() and QWidget::font().
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 geometry issues with windows.
Access functions:
QPoint | pos () const |
void | move ( int x, int y ) |
void | move ( const QPoint & ) |
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 geometry issues with windows.
By default, this property contains a value that depends on the user's platform and screen geometry.
Access functions:
QRect | rect () const |
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:
QSize | size () const |
void | resize ( int w, int h ) |
void | resize ( const QSize & ) |
See also pos, geometry, minimumSize, maximumSize, resizeEvent(), and adjustSize().
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().
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:
QSize | sizeIncrement () const |
void | setSizeIncrement ( const QSize & ) |
void | setSizeIncrement ( int w, int h ) |
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:
QSizePolicy | sizePolicy () const |
void | setSizePolicy ( QSizePolicy ) |
void | setSizePolicy ( QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical ) |
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:
QString | statusTip () const |
void | setStatusTip ( const QString & ) |
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.
Since Qt 4.5, Qt style sheets fully supports Mac OS X.
Warning: Qt style sheets are currently not supported for custom QStyle subclasses. We plan to address this in some future release.
This property was introduced in Qt 4.2.
Access functions:
QString | styleSheet () const |
void | setStyleSheet ( const QString & styleSheet ) |
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:
QString | toolTip () const |
void | setToolTip ( const QString & ) |
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 a widget enables all child widgets except top-level widgets or those that have been explicitly disabled. Re-enabling updates implicitly calls update() on the widget.
Access functions:
bool | updatesEnabled () const |
void | setUpdatesEnabled ( bool enable ) |
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:
bool | isVisible () const |
virtual void | setVisible ( bool visible ) |
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:
QString | whatsThis () const |
void | setWhatsThis ( const QString & ) |
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 geometry issues with windows.
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:
int | width () const |
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:
QString | windowFilePath () const |
void | setWindowFilePath ( const QString & filePath ) |
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:
Qt::WindowFlags | windowFlags () const |
void | setWindowFlags ( Qt::WindowFlags type ) |
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:
QIcon | windowIcon () const |
void | setWindowIcon ( const QIcon & icon ) |
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:
QString | windowIconText () const |
void | setWindowIconText ( const QString & ) |
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:
Qt::WindowModality | windowModality () const |
void | setWindowModality ( Qt::WindowModality windowModality ) |
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:
bool | isWindowModified () const |
void | setWindowModified ( bool ) |
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, Windows, and X11 platforms that support the Composite extension.
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:
qreal | windowOpacity () const |
void | setWindowOpacity ( qreal level ) |
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:
QString | windowTitle () const |
void | setWindowTitle ( const QString & ) |
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 geometry issues with windows.
By default, this property has a value of 0.
Access functions:
int | x () const |
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 geometry issues with windows.
By default, this property has a value of 0.
Access functions:
int | y () const |
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 does 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 and adding an action it already has will not cause the same action to be in the widget twice.
The ownership of action is not transferred to this QWidget.
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 its contents.
This function uses sizeHint() if it is valid, i.e., the size hint's width and height are >= 0. Otherwise, it sets the size to the children rectangle that covers all child widgets (the union of all child widget rectangles).
For windows, the screen size is also taken into account. If the sizeHint() is less than (200, 100) and the size policy is expanding, the window will be at least (200, 100). The maximum size of a window is 2/3 of the screen's width and height.
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, QEvent::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 function.
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 is called with the given event when Qt receives a window close request for a top-level widget from the window system.
By default, the event is accepted and the widget is closed. You can reimplement this function to change the way the widget responds to window close requests. For example, you can prevent the window from closing by calling ignore() on all events.
Main window applications typically use reimplementations of this function to check whether the user's work has been saved and ask for permission before closing. For example, the Application Example uses a helper function to determine whether or not to close the window:
void MainWindow::closeEvent(QCloseEvent *event) { if (maybeSave()) { writeSettings(); event->accept(); } else { event->ignore(); } }
See also event(), hide(), close(), QCloseEvent, and Application Example.
The contentsMargins function returns the widget's contents margins.
This function was introduced in Qt 4.6.
See also getContentsMargins(), setContentsMargins(), and contentsRect().
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 QDrag 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 QDrag and QDragLeaveEvent.
This event handler is called if a drag is in progress, and when any of the following conditions occur: 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 QDrag and QDragMoveEvent.
This event handler is called when the drag is dropped on 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 QDrag and QDropEvent.
Returns the effective window system identifier of the widget, i.e. the native parent's window system identifier.
If the widget is native, this function returns the native widget ID. Otherwise, the window ID of the first native parent widget, i.e., the top-level widget that contains this widget, is returned.
Note: We recommend that you do not store this value as it is likely to change at run-time.
This function was introduced in Qt 4.4.
See also nativeParentWidget().
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
QWidget calls this function after it has been fully constructed but before it is shown the very first time. You can call this function if you want to ensure that the widget is polished before doing an operation, e.g., the correct font size might be needed in the widget's sizeHint() reimplementation. Note that this function is called from the default implementation of sizeHint().
Polishing is useful for final initialization that must happen after all constructors (from base classes as well as from subclasses) have been called.
If you need to change some settings when a widget is polished, reimplement event() and handle the QEvent::Polish event type.
Note: The function is declared const so that it can be called from other const functions (e.g., sizeHint()).
See also event().
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().
Reimplemented from QObject::event().
This is the main event handler; it handles event event. You can reimplement this function in a subclass, but we recommend using one of the specialized event handlers instead.
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().
Mouse and tablet event handling is also slightly special: only when the widget is enabled, event() will call the specialized handlers such as mousePressEvent(); otherwise it will discard the event.
This function returns true if the event was recognized, otherwise it returns false. If the recognized event was accepted (see QEvent::accepted), any further processing such as event propagation to the parent widget stops.
See also closeEvent(), focusInEvent(), focusOutEvent(), enterEvent(), keyPressEvent(), keyReleaseEvent(), leaveEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), moveEvent(), paintEvent(), resizeEvent(), QObject::event(), and QObject::timerEvent().
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.
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 windows that do not specify a focusPolicy()).
See also focusOutEvent(), setFocusPolicy(), keyPressEvent(), keyReleaseEvent(), event(), and QFocusEvent.
Finds a new widget to give the keyboard focus to, as appropriate for Tab, and returns true if it can find a new widget, or false if it can't.
See also focusPreviousChild().
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it can't.
If next is true, this function searches forward, if next is false, it searches backward.
Sometimes, you will want to reimplement this function. For example, a web browser might reimplement it to move its "current active link" forward or backward, and call focusNextPrevChild() only when it reaches the last or first link on the "page".
Child widgets call focusNextPrevChild() on their parent widgets, but only the window that contains the child widgets decides where to redirect focus. By reimplementing this function for an object, you thus gain control of focus traversal for all child widgets.
See also focusNextChild() and focusPreviousChild().
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 windows that do not specify a focusPolicy()).
See also focusInEvent(), setFocusPolicy(), keyPressEvent(), keyReleaseEvent(), event(), and QFocusEvent.
Finds a new widget to give the keyboard focus to, as appropriate for Shift+Tab, and returns true if it can find a new widget, or false if it can't.
See also focusNextChild().
Returns the focus proxy, or 0 if there is no focus proxy.
See also setFocusProxy().
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.
Returns the font info for the widget's current font. Equivalent to QFontInto(widget->font()).
See also font(), fontMetrics(), and setFont().
Returns the font metrics for the widget's current font. Equivalent to QFontMetrics(widget->font()).
See also font(), fontInfo(), and setFont().
Returns the foreground role.
The foreground role defines the color from the widget's palette that is used to draw the foreground.
If no explicit foreground role is set, the function returns a role that contrasts with the background role.
See also setForegroundRole() and backgroundRole().
Returns the widget's contents margins for left, top, right, and bottom.
See also setContentsMargins() and contentsRect().
Returns the window system handle of the widget, for low-level access. Using this function is not portable.
An HDC acquired with getDC() has to be released with releaseDC().
Warning: Using this function is not portable.
Subscribes the widget to a given gesture with specific flags.
This function was introduced in Qt 4.6.
See also ungrabGesture() and QGestureEvent.
Grabs the keyboard input.
This widget receives 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().
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: Only visible widgets can grab mouse input. If isVisible() returns false for a widget, that widget cannot call grabMouse().
Note: (Mac OS X developers) For Cocoa, calling grabMouse() on a widget only works when the mouse is inside the frame of that widget. For Carbon, it works outside the widget's frame as well, like for Windows and X11.
See also releaseMouse(), grabKeyboard(), and releaseKeyboard().
This function overloads grabMouse().
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.
Note: (Mac OS X developers) See the note in QWidget::grabMouse().
See also releaseMouse(), grabKeyboard(), releaseKeyboard(), and setCursor().
Adds a shortcut to Qt's shortcut system that watches for the given key sequence in the given context. If the context is Qt::ApplicationShortcut, the shortcut applies to the application as a whole. Otherwise, it is either local to this widget, Qt::WidgetShortcut, or to the window itself, Qt::WindowShortcut.
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().
The graphicsEffect function returns a pointer to the widget's graphics effect.
If the widget has no graphics effect, 0 is returned.
This function was introduced in Qt 4.6.
See also setGraphicsEffect().
Returns the proxy widget for the corresponding embedded widget in a graphics view; otherwise returns 0.
This function was introduced in Qt 4.5.
See also QGraphicsProxyWidget::createProxyForChildWidget() and QGraphicsScene::addWidget().
Returns true if this widget currently has edit focus; otherwise false.
This feature is only available in Qt for Embedded Linux.
See also setEditFocus() and QApplication::keypadNavigationEnabled().
Returns the preferred height for this widget, given the width w.
If this widget has a layout, the default implementation returns the layout's preferred height. if there is no layout, the default implementation returns -1 indicating that the preferred height does not depend on the width.
Hides the widget. This function is equivalent to setVisible(false).
Note: If you are working with QDialog or its subclasses and you invoke the show() function after this function, the dialog will be displayed in its original position.
See also hideEvent(), isHidden(), show(), setVisible(), isVisible(), and close().
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.
Note: 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. After receiving a spontaneous hide event, a widget is still considered visible in the sense of isVisible().
See also visible, event(), and QHideEvent.
This function returns the QInputContext for this widget. By default the input context is inherited from the widgets parent. For toplevels it is inherited from QApplication.
You can override this and set a special input context for this widget by using the setInputContext() method.
See also setInputContext().
This event handler, for event event, can be reimplemented in a subclass to receive Input Method composition events. This handler is called when the state of the input method changes.
Note that when creating custom text editing widgets, the Qt::WA_InputMethodEnabled window attribute must be set explicitly (using the setAttribute() function) in order to receive input method events.
The default implementation calls event->ignore(), which rejects the Input Method event. See the QInputMethodEvent documentation for more details.
See also event() and QInputMethodEvent.
This method is only relevant for input widgets. It is used by the input method to query a set of properties of the widget to be able to support complex input method operations as support for surrounding text and reconversions.
query specifies which property is queried.
See also inputMethodEvent(), QInputMethodEvent, QInputContext, and inputMethodHints.
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.
A QWidget should only have one of each action.
See also removeAction(), addAction(), QMenu, contextMenuPolicy, and 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.
A QWidget can have at most one of each action.
See also removeAction(), QMenu, insertAction(), and contextMenuPolicy.
Returns true if this widget is a parent, (or grandparent and so on to any level), of the given child, and both widgets are within the same window; otherwise returns false.
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.