QWidget Class

Detailed Description

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:

  1. QWidget *parent = nullptr is the parent of the new widget. If it is nullptr (the default), the new widget will be a window. If not, it will be a child of parent, and be constrained by parent's geometry (unless you specify Qt::Window as window flag).

  2. Qt::WindowFlags f = { } (where available) sets the window flags; the default is suitable for almost all widgets, but to get, for example, a window without a window system frame, you must use special flags.

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.

Top-Level and Child Widgets

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.

A parent widget containing various child widgets.

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.

Composite Widgets

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 Widgets Tutorial.

Custom Widgets and Painting

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.

Size Hints and Size Policies

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.

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.

Events

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:

  • paintEvent() is called whenever the widget needs to be repainted. Every widget displaying custom content must implement it. Painting using a QPainter can only take place in a paintEvent() or a function called by a paintEvent().

  • resizeEvent() is called when the widget has been resized.

  • mousePressEvent() is called when a mouse button is pressed while the mouse cursor is inside the widget, or when the widget has grabbed the mouse using grabMouse(). Pressing the mouse without releasing it is effectively the same as calling grabMouse().

  • mouseReleaseEvent() is called when a mouse button is released. A widget receives mouse release events when it has received the corresponding mouse press event. This means that if the user presses the mouse inside your widget, then drags the mouse somewhere else before releasing the mouse button, your widget receives the release event. There is one exception: if a popup menu appears while the mouse button is held down, this popup immediately steals the mouse events.

  • mouseDoubleClickEvent() is called when the user double-clicks in the widget. If the user double-clicks, the widget receives a mouse press event, a mouse release event, (a mouse click event,) a second mouse press, this event and finally a second mouse release event. (Some mouse move events may also be received if the mouse is not held steady during this operation.) It is not possible to distinguish a click from a double-click until the second click arrives. (This is one reason why most GUI books recommend that double-clicks be an extension of single-clicks, rather than trigger a different action.)

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

  • keyPressEvent() is called whenever a key is pressed, and again when a key has been held down long enough for it to auto-repeat. The Tab and Shift+Tab keys are only passed to the widget if they are not used by the focus-change mechanisms. To force those keys to be processed by your widget, you must reimplement QWidget::event().

  • focusInEvent() is called when the widget gains keyboard focus (assuming you have called setFocusPolicy()). Well-behaved widgets indicate that they own the keyboard focus in a clear but discreet way.

  • focusOutEvent() is called when the widget loses keyboard focus.

You may be required to also reimplement some of the less common event handlers:

  • mouseMoveEvent() is called whenever the mouse moves while a mouse button is held down. This can be useful during drag and drop operations. If you call setMouseTracking(true), you get mouse move events even when no buttons are held down. (See also the Drag and Drop guide.)

  • keyReleaseEvent() is called whenever a key is released and while it is held down (if the key is auto-repeating). In that case, the widget will receive a pair of key release and key press event for every repeat. The Tab and Shift+Tab keys are only passed to the widget if they are not used by the focus-change mechanisms. To force those keys to be processed by your widget, you must reimplement QWidget::event().

  • wheelEvent() is called whenever the user turns the mouse wheel while the widget has the focus.

  • enterEvent() is called when the mouse enters the widget's screen space. (This excludes screen space owned by any of the widget's children.)

  • leaveEvent() is called when the mouse leaves the widget's screen space. If the mouse enters a child widget it will not cause a leaveEvent().

  • moveEvent() is called when the widget has been moved relative to its parent.

  • closeEvent() is called when the user closes the widget (or when close() is called).

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 Event System.

Groups of Functions and Properties

Context

Functions and Properties

Window functions

show(), hide(), raise(), lower(), close().

Top-level windows

windowModified, windowTitle, windowIcon, isActiveWindow, activateWindow(), minimized, showMinimized(), maximized, showMaximized(), fullScreen, showFullScreen(), showNormal().

Window contents

update(), repaint(), scroll().

Geometry

pos, x(), y(), rect, size, width(), height(), move(), resize(), sizePolicy, sizeHint(), minimumSizeHint(), updateGeometry(), layout(), frameGeometry, geometry, childrenRect, childrenRegion, adjustSize(), mapFromGlobal(), mapToGlobal(), mapFromParent(), mapToParent(), maximumSize, minimumSize, sizeIncrement, baseSize, setFixedSize()

Mode

visible, isVisibleTo(), enabled, isEnabledTo(), modal, isWindow(), mouseTracking, updatesEnabled, visibleRegion().

Look and feel

style(), setStyle(), styleSheet, cursor, font, palette, backgroundRole(), setBackgroundRole(), fontInfo(), fontMetrics().

Keyboard focus functions

focus, focusPolicy, setFocus(), clearFocus(), setTabOrder(), setFocusProxy(), focusNextChild(), focusPreviousChild().

Mouse and keyboard grabbing

grabMouse(), releaseMouse(), grabKeyboard(), releaseKeyboard(), mouseGrabber(), keyboardGrabber().

Event handlers

event(), mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), keyPressEvent(), keyReleaseEvent(), focusInEvent(), focusOutEvent(), wheelEvent(), enterEvent(), leaveEvent(), paintEvent(), moveEvent(), resizeEvent(), closeEvent(), dragEnterEvent(), dragMoveEvent(), dragLeaveEvent(), dropEvent(), childEvent(), showEvent(), hideEvent(), customEvent(). changeEvent(),

System functions

parentWidget(), window(), setParent(), winId(), find(), metric().

Context menu

contextMenuPolicy, contextMenuEvent(), customContextMenuRequested(), actions()

Interactive help

setToolTip(), setWhatsThis()

Widget Style Sheets

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.

Transparency and Double Buffering

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 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.

Image non disponible

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:

  • The left widget has no additional properties or widget attributes set. This default state suits most custom widgets using transparency, are irregularly-shaped, or do not paint over their entire area with an opaque brush.

  • The center widget has the autoFillBackground property set. This property is used with custom widgets that rely on the widget to supply a default background, and do not paint over their entire area with an opaque brush.

  • The right widget has the Qt::WA_OpaquePaintEvent widget attribute set. This indicates that the widget will paint over its entire area with opaque colors. The widget's area will initially be uninitialized, represented in the diagram with a red diagonal grid pattern that shines through the overpainted area. The Qt::WA_OpaquePaintArea attribute is useful for widgets that need to paint their own specialized contents quickly and do not need a default filled background.

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.

Image non disponible

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.

Creating Translucent Windows

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:

  • X11: This feature relies on the use of an X server that supports ARGB visuals and a compositing window manager.

  • Windows: The widget needs to have the Qt::FramelessWindowHint window flag set for the translucency to work.

  • macOS: The widget needs to have the Qt::FramelessWindowHint window flag set for the translucency to work.

Native Widgets vs Alien Widgets

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:

  1. Use the QT_USE_NATIVE_WINDOWS=1 in your environment.

  2. Set the Qt::AA_NativeWindows attribute on your application. All widgets will be native widgets.

  3. Set the Qt::WA_NativeWindow attribute on widgets: The widget itself and all of its ancestors will become native (unless Qt::WA_DontCreateNativeAncestors is set).

  4. Call QWidget::winId to enforce a native window (this implies 3).

  5. Set the Qt::WA_PaintOnScreen attribute to enforce a native window (this implies 3).

See Also

Member Type Documentation

 

enum QWidget::RenderFlag

flags QWidget::RenderFlags

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.

The RenderFlags type is a typedef for QFlags<RenderFlag>. It stores an OR combination of RenderFlag values.

Property Documentation

 

acceptDrops : bool

This property holds whether drop events are enabled for this widget

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

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

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

See also Drag and Drop

accessibleDescription : QString

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

The accessible description of a widget should convey what a widget does. While the accessibleName should be a short and concise string (e.g. Save), the description should give more context, such as Saves the current document.

This property has to be localized.

By default, this property contains an empty string and Qt falls back to using the tool tip to provide this information.

Access functions:

  • accessibleDescription() const

  • void setAccessibleDescription(const &description)

See Also

accessibleName : QString

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

This is the primary name by which assistive technology such as screen readers announce this widget. For most widgets setting this property is not required. For example for QPushButton the button's text will be used.

It is important to set this property when the widget does not provide any text. For example a button that only contains an icon needs to set this property to work with screen readers. The name should be short and equivalent to the visual information conveyed by the widget.

This property has to be localized.

By default, this property contains an empty string.

Access functions:

  • accessibleName() const

  • void setAccessibleName(const &name)

See Also

autoFillBackground : bool

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.

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.

Access functions:

  • bool autoFillBackground() const

  • void setAutoFillBackground(bool enabled)

See Also

baseSize : QSize

This property holds the base size of the widget

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

By default, for a newly-created widget, this property contains a size with zero width and height.

Access functions:

  • baseSize() const

  • void setBaseSize(const QSize &)

  • void setBaseSize(int basew, int baseh)

See Also

See also setSizeIncrement()

[read-only] childrenRect : const QRect

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:

  • childrenRect() const

See Also

See also childrenRegion(), geometry()

[read-only] childrenRegion : const QRegion

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:

  • childrenRegion() const

See Also

See also childrenRect(), geometry(), mask()

contextMenuPolicy : Qt::ContextMenuPolicy

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:

  • contextMenuPolicy() const

  • void setContextMenuPolicy( policy)

See Also

cursor : QCursor

This property holds the cursor shape for this widget

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

An editor widget might use an I-beam cursor:

 
Sélectionnez
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 QGuiApplication::setOverrideCursor().

Access functions:

  • cursor() const

  • void setCursor(const QCursor &)

  • void unsetCursor()

See Also

enabled : bool

This property holds whether the widget is enabled

In general an enabled widget handles keyboard and mouse events; a disabled widget does not. An exception is made with QAbstractButton.

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. It it not possible to explicitly enable a child widget which is not a window while its parent widget remains disabled.

By default, this property is true.

Access functions:

  • bool isEnabled() const

  • void setEnabled(bool)

See Also

[read-only] focus : const bool

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

By default, this property is false.

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

focusPolicy : Qt::FocusPolicy

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:

  • focusPolicy() const

  • void setFocusPolicy( policy)

See Also

font : QFont

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, and Windows 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.

If Qt Style Sheets are used on the same widget as setFont(), style sheets will take precedence if the settings conflict.

Access functions:

  • const &font() const

  • void setFont(const QFont &)

See Also

See also fontInfo(), fontMetrics()

[read-only] frameGeometry : const QRect

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:

  • frameGeometry() const

See Also

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

[read-only] frameSize : const QSize

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:

  • frameSize() const

[read-only] fullScreen : const bool

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

geometry : QRect

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

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

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

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 &geometry() const

  • void setGeometry(int x, int y, int w, int h)

  • void setGeometry(const QRect &)

See Also

[read-only] height : const int

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.

By default, this property contains a value that depends on the user's platform and screen geometry.

Access functions:

  • int height() const

See Also

See also geometry, width, size

inputMethodHints : Qt::InputMethodHints

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.

Some widgets require certain flags in order to work as intended. To set a flag, do w->setInputMethodHints(w->inputMethodHints()|f) instead of w->setInputMethodHints(f).

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.

Access functions:

  • inputMethodHints() const

  • void setInputMethodHints( hints)

See Also

See also inputMethodQuery()

[read-only] isActiveWindow : const bool

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

layoutDirection : Qt::LayoutDirection

This property holds the layout direction for this widget.

This method no longer affects text layout direction since Qt 4.7.

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:

  • layoutDirection() const

  • void setLayoutDirection( direction)

  • void unsetLayoutDirection()

See Also

locale : QLocale

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.

Access functions:

  • locale() const

  • void setLocale(const &locale)

  • void unsetLocale()

See Also

[read-only] maximized : const bool

This property holds whether this widget is maximized

This property is only relevant for windows.

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

maximumHeight : int

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.

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 : QSize

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.

The definition of the QWIDGETSIZE_MAX macro limits the maximum size of widgets.

Access functions:

  • maximumSize() const

  • void setMaximumSize(const QSize &)

  • void setMaximumSize(int maxw, int maxh)

See Also

maximumWidth : int

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.

The definition of the QWIDGETSIZE_MAX macro limits the maximum size of widgets.

Access functions:

  • int maximumWidth() const

  • void setMaximumWidth(int maxw)

See Also

[read-only] minimized : const bool

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

minimumHeight : int

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 : QSize

This property holds the widget's minimum size

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

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:

  • minimumSize() const

  • void setMinimumSize(const QSize &)

  • void setMinimumSize(int minw, int minh)

See Also

[read-only] minimumSizeHint : const QSize

This property holds the recommended minimum size for the widget

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

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

QLayout will never resize a widget to a size smaller than 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 minimumSizeHint() const

See Also

minimumWidth : int

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

[read-only] modal : const bool

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

mouseTracking : bool

This property holds whether mouse tracking is enabled for the widget

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

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

Access functions:

  • bool hasMouseTracking() const

  • void setMouseTracking(bool enable)

See Also

See also mouseMoveEvent()

[read-only] normalGeometry : const QRect

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

If the widget is already in this state the normal geometry will reflect the widget's current geometry().

For child widgets this property always holds an empty rectangle.

By default, this property contains an empty rectangle.

Access functions:

  • normalGeometry() const

See Also

palette : QPalette