Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QWidget Class Reference

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

#include <qwidget.h>

Inherits QObject, and QPaintDevice.

Inherited by BasicOperations, ButtonWidget, CombinedTransformation, DummyWidget, MyButtonWidget, MyClass, MyWidget, MyWidget, MyWidget, QAbstractButton, QAbstractSlider, QAbstractSpinBox, QAlphaWidget, QBalloonTip, QCalendarPopup, QCalendarWidget, QColumnViewGrip, QComboBox, QComboBoxPrivateScroller, QCupsJobWidget, QDialog, QDialogButtonBox, QDockWidget, QFocusFrame, QFrame, QGroupBox, QKeySequenceEdit, QLineEdit, QMainWindow, QMdi::ControlLabel, QMdi::ControllerWidget, QMdiSubWindow, QMenu, QMenuBar, QMenuPrivate::ScrollerTearOffItem, QMovableTabWidget, QOpenGLWidget, QPagePreview, QPageSetupWidget, QPdfPageSelector, QPrintPreviewWidget, QProgressBar, QQuickWidget, QRhiWidget, QRollEffect, QRubberBand, QSizeGrip, QSplashScreen, QSplitterHandle, QStatusBar, QSvgWidget, QSystemTrayIconSys, QTabBar, QTabWidget, QToolBar, QToolBarSeparator, QUnixPrintWidget, QVideoWidget, QWhatsThat, QWindowContainer, QWizardAntiFlickerWidget, QWizardHeader, QWizardPage, QtPrivate::QColorLuminancePicker, QtPrivate::QColorShower, QtPrivate::QWellArray, SimpleTransformation, Widget, Widget, Widget, Widget, Widget, Widget, Window, Window, Window, doc_src_coordsys::SnippetWrappers, droparea::DropArea, dropevents::Window, droprectangle::Window, plaintextlayout::Window, src_gui_image_qicon::MyWidget, src_gui_itemviews_qstandarditemmodel::MyWidget, src_gui_kernel_qguiapplication::MyMainWidget, src_gui_kernel_qkeysequence::Wrapper, src_gui_painting_qpainter2::MyWidget, src_gui_painting_qpainter::MyWidget, and src_gui_util_qvalidator::Wrapper.

+ Collaboration diagram for QWidget:

Public Types

enum  RenderFlag { DrawWindowBackground = 0x1 , DrawChildren = 0x2 , IgnoreMask = 0x4 }
 This enum describes how to render the widget when calling QWidget::render(). More...
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1 , PdmHeight , PdmWidthMM , PdmHeightMM ,
  PdmNumColors , PdmDepth , PdmDpiX , PdmDpiY ,
  PdmPhysicalDpiX , PdmPhysicalDpiY , PdmDevicePixelRatio , PdmDevicePixelRatioScaled
}
 

Public Slots

void setEnabled (bool)
 
void setDisabled (bool)
 Disables widget input events if disable is true; otherwise enables input events.
 
void setWindowModified (bool)
 
void setWindowTitle (const QString &)
 
void setStyleSheet (const QString &styleSheet)
 
void setFocus ()
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the \l{isActiveWindow()}{active window}.
 
void update ()
 Updates the widget unless updates are disabled or the widget is hidden.
 
void repaint ()
 Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the widget is hidden.
 
virtual void setVisible (bool visible)
 
void setHidden (bool hidden)
 Convenience function, equivalent to setVisible(!hidden).
 
void show ()
 Shows the widget and its child widgets.
 
void hide ()
 Hides the widget.
 
void showMinimized ()
 Shows the widget minimized, as an icon.
 
void showMaximized ()
 Shows the widget maximized.
 
void showFullScreen ()
 Shows the widget in full-screen mode.
 
void showNormal ()
 Restores the widget after it has been maximized or minimized.
 
bool close ()
 Closes this widget.
 
void raise ()
 Raises this widget to the top of the parent widget's stack.
 
void lower ()
 Lowers the widget to the bottom of the parent widget's stack.
 
- Public Slots inherited from QObject
void deleteLater ()
 \threadsafe
 

Signals

void windowTitleChanged (const QString &title)
 This signal is emitted when the window's title has changed, with the new title as an argument.
 
void windowIconChanged (const QIcon &icon)
 This signal is emitted when the window's icon has changed, with the new icon as an argument.
 
void windowIconTextChanged (const QString &iconText)
 This signal is emitted when the window's icon text has changed, with the new iconText as an argument.
 
void customContextMenuRequested (const QPoint &pos)
 This signal is emitted when the widget's \l contextMenuPolicy is Qt::CustomContextMenu, and the user has requested a context menu on the widget.
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked.
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 This signal is emitted after the object's name has been changed.
 

Public Member Functions

 QWidget (QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
 Constructs a widget which is a child of parent, with widget flags set to f.
 
 ~QWidget ()
 Destroys the widget.
 
int devType () const override
 
WId winId () const
 Returns the window system identifier of the widget.
 
void createWinId ()
 
WId internalWinId () const
 
WId effectiveWinId () const
 
QStylestyle () const
 
void setStyle (QStyle *)
 Sets the widget's GUI style to style.
 
bool isWindow () const
 Returns true if the widget is an independent window, otherwise returns false.
 
bool isModal () const
 
Qt::WindowModality windowModality () const
 
void setWindowModality (Qt::WindowModality windowModality)
 
bool isEnabled () const
 
bool isEnabledTo (const QWidget *) const
 Returns true if this widget would become enabled if ancestor is enabled; otherwise returns false.
 
QRect frameGeometry () const
 
const QRectgeometry () const
 
QRect normalGeometry () const
 
int x () const
 
int y () const
 
QPoint pos () const
 
QSize frameSize () const
 
QSize size () const
 
int width () const
 
int height () const
 
QRect rect () const
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
QSize minimumSize () const
 
QSize maximumSize () const
 
int minimumWidth () const
 
int minimumHeight () const
 
int maximumWidth () const
 
int maximumHeight () const
 
void setMinimumSize (const QSize &)
 
void setMinimumSize (int minw, int minh)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This function corresponds to setMinimumSize(QSize(minw, minh)).
 
void setMaximumSize (const QSize &)
 
void setMaximumSize (int maxw, int maxh)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This function corresponds to setMaximumSize(QSize(maxw, maxh)).
 
void setMinimumWidth (int minw)
 
void setMinimumHeight (int minh)
 
void setMaximumWidth (int maxw)
 
void setMaximumHeight (int maxh)
 
QSize sizeIncrement () const
 
void setSizeIncrement (const QSize &)
 
void setSizeIncrement (int w, int h)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the x (width) size increment to w and the y (height) size increment to h.
 
QSize baseSize () const
 
void setBaseSize (const QSize &)
 
void setBaseSize (int basew, int baseh)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This corresponds to setBaseSize(QSize(basew, baseh)).
 
void setFixedSize (const QSize &)
 Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing or shrinking.
 
void setFixedSize (int w, int h)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the width of the widget to w and the height to h.
 
void setFixedWidth (int w)
 Sets both the minimum and maximum width of the widget to w without changing the heights.
 
void setFixedHeight (int h)
 Sets both the minimum and maximum heights of the widget to h without changing the widths.
 
QPointF mapToGlobal (const QPointF &) const
 Translates the widget coordinate pos to global screen coordinates.
 
QPoint mapToGlobal (const QPoint &) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QPointF mapFromGlobal (const QPointF &) const
 Translates the global screen coordinate pos to widget coordinates.
 
QPoint mapFromGlobal (const QPoint &) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QPointF mapToParent (const QPointF &) const
 Translates the widget coordinate pos to a coordinate in the parent widget.
 
QPoint mapToParent (const QPoint &) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QPointF mapFromParent (const QPointF &) const
 Translates the parent widget coordinate pos to widget coordinates.
 
QPoint mapFromParent (const QPoint &) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QPointF mapTo (const QWidget *, const QPointF &) const
 Translates the widget coordinate pos to the coordinate system of parent.
 
QPoint mapTo (const QWidget *, const QPoint &) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QPointF mapFrom (const QWidget *, const QPointF &) const
 Translates the widget coordinate pos from the coordinate system of parent to this widget's coordinate system.
 
QPoint mapFrom (const QWidget *, const QPoint &) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QWidgetwindow () const
 Returns the window for this widget, i.e.
 
QWidgetnativeParentWidget () const
 
QWidgettopLevelWidget () const
 
const QPalettepalette () const
 
void setPalette (const QPalette &)
 
void setBackgroundRole (QPalette::ColorRole)
 Sets the background role of the widget to role.
 
QPalette::ColorRole backgroundRole () const
 Returns the background role of the widget.
 
void setForegroundRole (QPalette::ColorRole)
 Sets the foreground role of the widget to role.
 
QPalette::ColorRole foregroundRole () const
 Returns the foreground role.
 
const QFontfont () const
 
void setFont (const QFont &)
 
QFontMetrics fontMetrics () const
 Returns the font metrics for the widget's current font.
 
QFontInfo fontInfo () const
 Returns the font info for the widget's current font.
 
QCursor cursor () const
 
void setCursor (const QCursor &)
 
void unsetCursor ()
 
void setMouseTracking (bool enable)
 
bool hasMouseTracking () const
 
bool underMouse () const
 Returns true if the widget is under the mouse cursor; otherwise returns false.
 
void setTabletTracking (bool enable)
 
bool hasTabletTracking () const
 
void setMask (const QBitmap &)
 Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible.
 
void setMask (const QRegion &)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Causes only the parts of the widget which overlap region to be visible.
 
QRegion mask () const
 Returns the mask currently set on a widget.
 
void clearMask ()
 Removes any mask set by setMask().
 
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))
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Renders the widget into the painter's QPainter::device().
 
Q_INVOKABLE QPixmap grab (const QRect &rectangle=QRect(QPoint(0, 0), QSize(-1, -1)))
 
void grabGesture (Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
 Subscribes the widget to a given gesture with specific flags.
 
void ungrabGesture (Qt::GestureType type)
 Unsubscribes the widget from a given gesture type.
 
QString styleSheet () const
 
QString windowTitle () const
 
void setWindowIcon (const QIcon &icon)
 
QIcon windowIcon () const
 
void setWindowIconText (const QString &)
 
QString windowIconText () const
 
void setWindowRole (const QString &)
 Sets the window's role to role.
 
QString windowRole () const
 Returns the window's role, or an empty string.
 
void setWindowFilePath (const QString &filePath)
 
QString windowFilePath () const
 
void setWindowOpacity (qreal level)
 
qreal windowOpacity () const
 
bool isWindowModified () const
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
Qt::LayoutDirection layoutDirection () const
 
void unsetLayoutDirection ()
 
void setLocale (const QLocale &locale)
 
QLocale locale () const
 
void unsetLocale ()
 
bool isRightToLeft () const
 
bool isLeftToRight () const
 
bool isActiveWindow () const
 
void activateWindow ()
 Sets the top-level widget containing this widget to be the active window.
 
void clearFocus ()
 Takes keyboard input focus from the widget.
 
void setFocus (Qt::FocusReason reason)
 Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the \l{isActiveWindow()}{active window}.
 
Qt::FocusPolicy focusPolicy () const
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
bool hasFocus () const
 
void setFocusProxy (QWidget *)
 Sets the widget's focus proxy to widget w.
 
QWidgetfocusProxy () const
 Returns the focus proxy, or \nullptr if there is no focus proxy.
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void grabMouse ()
 Grabs the mouse input.
 
void grabMouse (const QCursor &)
 
void releaseMouse ()
 Releases the mouse grab.
 
void grabKeyboard ()
 Grabs the keyboard input.
 
void releaseKeyboard ()
 Releases the keyboard grab.
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 Adds a shortcut to Qt's shortcut system that watches for the given key sequence in the given context.
 
void releaseShortcut (int id)
 Removes the shortcut with the given id from Qt's shortcut system.
 
void setShortcutEnabled (int id, bool enable=true)
 If enable is true, the shortcut with the given id is enabled; otherwise the shortcut is disabled.
 
void setShortcutAutoRepeat (int id, bool enable=true)
 
bool updatesEnabled () const
 
void setUpdatesEnabled (bool enable)
 
void update (int x, int y, int w, int h)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version updates a rectangle (x, y, w, h) inside the widget.
 
void update (const QRect &)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version updates a rectangle rect inside the widget.
 
void update (const QRegion &)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version repaints a region rgn inside the widget.
 
void repaint (int x, int y, int w, int h)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version repaints a rectangle (x, y, w, h) inside the widget.
 
void repaint (const QRect &)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version repaints a rectangle rect inside the widget.
 
void repaint (const QRegion &)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version repaints a region rgn inside the widget.
 
void stackUnder (QWidget *)
 Places the widget under w in the parent widget's stack.
 
void move (int x, int y)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This corresponds to move(QPoint(x, y)).
 
void move (const QPoint &)
 
void resize (int w, int h)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This corresponds to resize(QSize(w, h)).
 
void resize (const QSize &)
 
void setGeometry (int x, int y, int w, int h)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This corresponds to setGeometry(QRect(x, y, w, h)).
 
void setGeometry (const QRect &)
 
QByteArray saveGeometry () const
 
bool restoreGeometry (const QByteArray &geometry)
 
void adjustSize ()
 Adjusts the size of the widget to fit its contents.
 
bool isVisible () const
 
bool isVisibleTo (const QWidget *) const
 Returns true if this widget would become visible if ancestor is shown; otherwise returns false.
 
bool isHidden () const
 Returns true if the widget is hidden, otherwise returns false.
 
bool isMinimized () const
 
bool isMaximized () const
 
bool isFullScreen () const
 
Qt::WindowStates windowState () const
 Returns the current window state.
 
void setWindowState (Qt::WindowStates state)
 Sets the window state to windowState.
 
void overrideWindowState (Qt::WindowStates state)
 
virtual QSize sizeHint () const
 
virtual QSize minimumSizeHint () const
 
QSizePolicy sizePolicy () const
 
void setSizePolicy (QSizePolicy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the size policy of the widget to horizontal and vertical, with standard stretch and no height-for-width.
 
virtual int heightForWidth (int) const
 Returns the preferred height for this widget, given the width w.
 
virtual bool hasHeightForWidth () const
 
QRegion visibleRegion () const
 Returns the unobscured region where paint events can occur.
 
void setContentsMargins (int left, int top, int right, int bottom)
 Sets the margins around the contents of the widget to have the sizes left, top, right, and bottom.
 
void setContentsMargins (const QMargins &margins)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QMargins contentsMargins () const
 The contentsMargins function returns the widget's contents margins.
 
QRect contentsRect () const
 Returns the area inside the widget's margins.
 
QLayoutlayout () const
 Returns the layout manager that is installed on this widget, or \nullptr if no layout manager is installed.
 
void setLayout (QLayout *)
 Sets the layout manager for this widget to layout.
 
void updateGeometry ()
 Notifies the layout system that this widget has changed and may need to change geometry.
 
void setParent (QWidget *parent)
 Sets the parent of the widget to parent, and resets the window flags.
 
void setParent (QWidget *parent, Qt::WindowFlags f)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This function also takes widget flags, f as an argument.
 
void scroll (int dx, int dy)
 Scrolls the widget including its children dx pixels to the right and dy downward.
 
void scroll (int dx, int dy, const QRect &)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version only scrolls r and does not move the children of the widget.
 
QWidgetfocusWidget () const
 Returns the last child of this widget that setFocus had been called on.
 
QWidgetnextInFocusChain () const
 Returns the next widget in this widget's focus chain.
 
QWidgetpreviousInFocusChain () const
 The previousInFocusChain function returns the previous widget in this widget's focus chain.
 
bool acceptDrops () const
 
void setAcceptDrops (bool on)
 
void addAction (QAction *action)
 Appends the action action to this widget's list of actions.
 
void addActions (const QList< QAction * > &actions)
 Appends the actions actions to this widget's list of actions.
 
void insertActions (QAction *before, const QList< QAction * > &actions)
 Inserts the actions actions to this widget's list of actions, before the action before.
 
void insertAction (QAction *before, QAction *action)
 Inserts the action action to this widget's list of actions, before the action before.
 
void removeAction (QAction *action)
 Removes the action action from this widget's list of actions.
 
QList< QAction * > actions () const
 Returns the (possibly empty) list of this widget's actions.
 
QActionaddAction (const QString &text)
 
QActionaddAction (const QIcon &icon, const QString &text)
 
QActionaddAction (const QString &text, const QObject *receiver, const char *member, Qt::ConnectionType type=Qt::AutoConnection)
 
QActionaddAction (const QIcon &icon, const QString &text, const QObject *receiver, const char *member, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename... Args, typename = compatible_action_slot_args<Args...>>
QActionaddAction (const QString &text, Args &&...args)
 
template<typename... Args, typename = compatible_action_slot_args<Args...>>
QActionaddAction (const QIcon &icon, const QString &text, Args &&...args)
 
QWidgetparentWidget () const
 Returns the parent of this widget, or \nullptr if it does not have any parent widget.
 
void setWindowFlags (Qt::WindowFlags type)
 
Qt::WindowFlags windowFlags () const
 Window flags are a combination of a type (e.g.
 
void setWindowFlag (Qt::WindowType, bool on=true)
 
void overrideWindowFlags (Qt::WindowFlags type)
 Sets the window flags for the widget to flags, without telling the window system.
 
Qt::WindowType windowType () const
 Returns the window type of this widget.
 
QWidgetchildAt (int x, int y) const
 Returns the visible child widget at the position ({x}, {y}) in the widget's coordinate system.
 
QWidgetchildAt (const QPoint &p) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the visible child widget at point p in the widget's own coordinate system.
 
void setAttribute (Qt::WidgetAttribute, bool on=true)
 Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
 
bool testAttribute (Qt::WidgetAttribute) const
 Returns true if attribute attribute is set on this widget; otherwise returns false.
 
QPaintEnginepaintEngine () const override
 Returns the widget's paint engine.
 
void ensurePolished () const
 Ensures that the widget and its children have been polished by QStyle (i.e., have a proper font and palette).
 
bool isAncestorOf (const QWidget *child) const
 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.
 
bool autoFillBackground () const
 
void setAutoFillBackground (bool enabled)
 
QBackingStorebackingStore () const
 
QWindowwindowHandle () const
 If this is a native widget, return the associated QWindow.
 
QScreenscreen () const
 Returns the screen the widget is on.
 
void setScreen (QScreen *)
 Sets the screen on which the widget should be shown to screen.
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery) const
 This method is only relevant for input widgets.
 
Qt::InputMethodHints inputMethodHints () const
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 Constructs an object with parent object parent.
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects.
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 Filters events if this object has been installed as an event filter for the watched object.
 
QString objectName () const
 
Q_WEAK_OVERLOAD void setObjectName (const QString &name)
 Sets the object's name to name.
 
void setObjectName (QAnyStringView name)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false.
 
bool isWindowType () const
 Returns true if the object is a window; otherwise returns false.
 
bool isQuickItemType () const
 Returns true if the object is a QQuickItem; otherwise returns false.
 
bool signalsBlocked () const noexcept
 Returns true if signals are blocked; otherwise returns false.
 
bool blockSignals (bool b) noexcept
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it).
 
QThreadthread () const
 Returns the thread in which the object lives.
 
bool moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL)
 Changes the thread affinity for this object and its children and returns true on success.
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds.
 
int startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 Kills the timer with timer identifier, id.
 
void killTimer (Qt::TimerId id)
 
template<typename T >
findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object.
 
template<typename T >
QList< T > findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects.
 
template<typename T >
findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T >
QList< T > findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const QObjectListchildren () const
 Returns a list of child objects.
 
void setParent (QObject *parent)
 Makes the object a child of parent.
 
void installEventFilter (QObject *filterObj)
 Installs an event filter filterObj on this object.
 
void removeEventFilter (QObject *obj)
 Removes an event filter object obj from this object.
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 Dumps a tree of children to the debug output.
 
void dumpObjectInfo () const
 Dumps information about signal connections, etc.
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value.
 
bool setProperty (const char *name, QVariant &&value)
 
QVariant property (const char *name) const
 Returns the value of the object's name property.
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 Returns a pointer to the parent object.
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false.
 
- Public Member Functions inherited from QPaintDevice
virtual ~QPaintDevice ()
 
bool paintingActive () const
 
int width () const
 
int height () const
 
int widthMM () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
qreal devicePixelRatio () const
 
qreal devicePixelRatioF () const
 
int colorCount () const
 
int depth () const
 

Static Public Member Functions

static void setTabOrder (QWidget *, QWidget *)
 Puts the second widget after the first widget in the focus order.
 
static void setTabOrder (std::initializer_list< QWidget * > widgets)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
static QWidgetmouseGrabber ()
 Returns the widget that is currently grabbing the mouse input.
 
static QWidgetkeyboardGrabber ()
 Returns the widget that is currently grabbing the keyboard input.
 
static QWidgetfind (WId)
 Returns a pointer to the widget with window identifier/handle id.
 
static QWidgetcreateWindowContainer (QWindow *window, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
 Creates a QWidget that makes it possible to embed window into a QWidget-based application.
 
- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 \threadsafe
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 \threadsafe
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 Disconnect a connection.
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Static Public Member Functions inherited from QPaintDevice
static qreal devicePixelRatioFScale ()
 

Protected Slots

void updateMicroFocus (Qt::InputMethodQuery query=Qt::ImQueryAll)
 Updates the widget's micro focus and informs input methods that the state specified by query has changed.
 

Protected Member Functions

bool event (QEvent *event) override
 This is the main event handler; it handles event event.
 
virtual void mousePressEvent (QMouseEvent *event)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse press events for the widget.
 
virtual void mouseReleaseEvent (QMouseEvent *event)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse release events for the widget.
 
virtual void mouseDoubleClickEvent (QMouseEvent *event)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse double click events for the widget.
 
virtual void mouseMoveEvent (QMouseEvent *event)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse move events for the widget.
 
virtual void keyPressEvent (QKeyEvent *event)
 This event handler, for event event, can be reimplemented in a subclass to receive key press events for the widget.
 
virtual void keyReleaseEvent (QKeyEvent *event)
 This event handler, for event event, can be reimplemented in a subclass to receive key release events for the widget.
 
virtual void focusInEvent (QFocusEvent *event)
 This event handler can be reimplemented in a subclass to receive keyboard focus events (focus received) for the widget.
 
virtual void focusOutEvent (QFocusEvent *event)
 This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) for the widget.
 
virtual void enterEvent (QEnterEvent *event)
 This event handler can be reimplemented in a subclass to receive widget enter events which are passed in the event parameter.
 
virtual void leaveEvent (QEvent *event)
 This event handler can be reimplemented in a subclass to receive widget leave events which are passed in the event parameter.
 
virtual void paintEvent (QPaintEvent *event)
 This event handler can be reimplemented in a subclass to receive paint events passed in event.
 
virtual void moveEvent (QMoveEvent *event)
 This event handler can be reimplemented in a subclass to receive widget move events which are passed in the event parameter.
 
virtual void resizeEvent (QResizeEvent *event)
 This event handler can be reimplemented in a subclass to receive widget resize events which are passed in the event parameter.
 
virtual void closeEvent (QCloseEvent *event)
 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.
 
virtual void contextMenuEvent (QContextMenuEvent *event)
 This event handler, for event event, can be reimplemented in a subclass to receive widget context menu events.
 
virtual void actionEvent (QActionEvent *event)
 This event handler is called with the given event whenever the widget's actions are changed.
 
virtual void showEvent (QShowEvent *event)
 This event handler can be reimplemented in a subclass to receive widget show events which are passed in the event parameter.
 
virtual void hideEvent (QHideEvent *event)
 This event handler can be reimplemented in a subclass to receive widget hide events.
 
virtual bool nativeEvent (const QByteArray &eventType, void *message, qintptr *result)
 This special event handler can be reimplemented in a subclass to receive native platform events identified by eventType which are passed in the message parameter.
 
virtual void changeEvent (QEvent *)
 This event handler can be reimplemented to handle state changes.
 
int metric (PaintDeviceMetric) const override
 Internal implementation of the virtual QPaintDevice::metric() function.
 
void initPainter (QPainter *painter) const override
 Initializes the painter pen, background and font to the same as the given widget's.
 
QPaintDeviceredirected (QPoint *offset) const override
 
QPaintersharedPainter () const override
 
virtual void inputMethodEvent (QInputMethodEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive Input Method composition events.
 
void create (WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
 Creates a new widget window.
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 Frees up window system resources.
 
virtual bool focusNextPrevChild (bool next)
 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.
 
bool focusNextChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for \uicontrol Tab, and returns true if it can find a new widget, or false if it can't.
 
bool focusPreviousChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for \uicontrol Shift+Tab, and returns true if it can find a new widget, or false if it can't.
 
 QWidget (QWidgetPrivate &d, QWidget *parent, Qt::WindowFlags f)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr.
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal.
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 This event handler can be reimplemented in a subclass to receive timer events for the object.
 
virtual void childEvent (QChildEvent *event)
 This event handler can be reimplemented in a subclass to receive child events.
 
virtual void customEvent (QEvent *event)
 This event handler can be reimplemented in a subclass to receive custom events.
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 
- Protected Member Functions inherited from QPaintDevice
 QPaintDevice () noexcept
 

Properties

bool modal
 whether the widget is a modal widget
 
Qt::WindowModality windowModality
 which windows are blocked by the modal widget
 
bool enabled
 whether the widget is enabled
 
QRect geometry
 the geometry of the widget relative to its parent and excluding the window frame
 
QRect frameGeometry
 geometry of the widget relative to its parent including any window frame
 
QRect normalGeometry
 the geometry of the widget as it will appear when shown as a normal (not maximized or full screen) top-level widget
 
int x
 the x coordinate of the widget relative to its parent including any window frame
 
int y
 the y coordinate of the widget relative to its parent and including any window frame
 
QPoint pos
 the position of the widget within its parent widget
 
QSize frameSize
 the size of the widget including any window frame
 
QSize size
 the size of the widget excluding any window frame
 
int width
 the width of the widget excluding any window frame
 
int height
 the height of the widget excluding any window frame
 
QRect rect
 the internal geometry of the widget excluding any window frame
 
QRect childrenRect
 the bounding rectangle of the widget's children
 
QRegion childrenRegion
 the combined region occupied by the widget's children
 
QSizePolicy sizePolicy
 the default layout behavior of the widget
 
QSize minimumSize
 the widget's minimum size
 
QSize maximumSize
 the widget's maximum size in pixels
 
int minimumWidth
 the widget's minimum width in pixels
 
int minimumHeight
 the widget's minimum height in pixels
 
int maximumWidth
 the widget's maximum width in pixels
 
int maximumHeight
 the widget's maximum height in pixels
 
QSize sizeIncrement
 the size increment of the widget
 
QSize baseSize
 the base size of the widget
 
QPalette palette
 the widget's palette
 
QFont font
 the font currently set for the widget
 
QCursor cursor
 the cursor shape for this widget
 
bool mouseTracking
 whether mouse tracking is enabled for the widget
 
bool tabletTracking
 whether tablet tracking is enabled for the widget
 
bool isActiveWindow
 whether this widget's window is the active window
 
Qt::FocusPolicy focusPolicy
 the way the widget accepts keyboard focus
 
bool focus
 whether this widget (or its focus proxy) has the keyboard input focus
 
Qt::ContextMenuPolicy contextMenuPolicy
 how the widget shows a context menu
 
bool updatesEnabled
 whether updates are enabled
 
bool visible
 whether the widget is visible
 
bool minimized
 whether this widget is minimized (iconified)
 
bool maximized
 whether this widget is maximized
 
bool fullScreen
 whether the widget is shown in full screen mode
 
QSize sizeHint
 the recommended size for the widget
 
QSize minimumSizeHint
 the recommended minimum size for the widget
 
bool acceptDrops
 whether drop events are enabled for this widget
 
QString windowTitle
 the window title (caption)
 
QIcon windowIcon
 the widget's icon
 
QString windowIconText
 the text to be displayed on the icon of a minimized window
 
double windowOpacity
 The level of opacity for the window.
 
bool windowModified
 whether the document shown in the window has unsaved changes
 
Qt::LayoutDirection layoutDirection
 the layout direction for this widget.
 
bool autoFillBackground
 whether the widget background is filled automatically
 
QString styleSheet
 the widget's style sheet
 
QLocale locale
 the widget's locale
 
QString windowFilePath
 the file path associated with a widget
 
Qt::InputMethodHints inputMethodHints
 What input method specific hints the widget has.
 
- Properties inherited from QObject
QString objectName
 the name of this object
 

Friends

class QDataWidgetMapperPrivate
 
class QBackingStoreDevice
 
class QWidgetRepaintManager
 
class QApplication
 
class QApplicationPrivate
 
class QGuiApplication
 
class QGuiApplicationPrivate
 
class QBaseApplication
 
class QPainter
 
class QPainterPrivate
 
class QPixmap
 
class QFontMetrics
 
class QFontInfo
 
class QLayout
 
class QWidgetItem
 
class QWidgetItemV2
 
class QX11PaintEngine
 
class QWin32PaintEngine
 
class QShortcutPrivate
 
class QWindowSurface
 
class QGraphicsProxyWidget
 
class QGraphicsProxyWidgetPrivate
 
class QStyleSheetStyle
 
struct QWidgetExceptionCleaner
 
class QWidgetWindow
 
class QAccessibleWidget
 
class QAccessibleTable
 
class QAccessibleTabButton
 
class QGestureManager
 
class QWinNativePanGestureRecognizer
 
class QWidgetEffectSourcePrivate
 
Q_WIDGETS_EXPORT QWidgetDataqt_qwidget_data (QWidget *widget)
 
Q_WIDGETS_EXPORT QWidgetPrivateqt_widget_private (QWidget *widget)
 

Related Symbols

(Note that these are not member symbols.)

 setupUi (QWidget *widget)
 \macro QWIDGETSIZE_MAX
 

Additional Inherited Members

- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Protected Attributes inherited from QPaintDevice
ushort painters
 

Detailed Description

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

\inmodule QtWidgets

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 \l{Qt::WindowFlags}{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:

\list 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).
  • {Qt::WindowFlags f = { }} (where available) sets the window flags; the default is suitable for most widgets, but to get, for example, a window without a window system frame, you must use special flags. \endlist

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 that provide real functionality, such as QLabel, QPushButton, QListWidget, and QTabWidget.

Definition at line 98 of file qwidget.h.

Member Enumeration Documentation

◆ RenderFlag

This enum describes how to render the widget when calling QWidget::render().

\value DrawWindowBackground 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.

\value DrawChildren If you enable this option, the widget's children are rendered recursively into the target. By default, this option is enabled.

\value IgnoreMask If you enable this option, the widget's QWidget::mask() is ignored when rendering into the target. By default, this option is disabled.

Since
4.3
Enumerator
DrawWindowBackground 
DrawChildren 
IgnoreMask 

Definition at line 206 of file qwidget.h.

Constructor & Destructor Documentation

◆ QWidget() [1/2]

QWidget::QWidget ( QWidget * parent = nullptr,
Qt::WindowFlags f = Qt::WindowFlags() )
explicit

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

If parent is \nullptr, 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 \nullptr). To customize the frame, use a value composed from the bitwise OR of any of the \l{Qt::WindowFlags}{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

Definition at line 853 of file qwidget.cpp.

References QWidgetExceptionCleaner::cleanup(), QObject::parent(), QT_CATCH, QT_RETHROW, and QT_TRY.

+ Here is the call graph for this function:

◆ ~QWidget()

◆ QWidget() [2/2]

QWidget::QWidget ( QWidgetPrivate & dd,
QWidget * parent,
Qt::WindowFlags f )
protected

Definition at line 867 of file qwidget.cpp.

References QWidgetExceptionCleaner::cleanup(), d, QObject::parent(), QT_CATCH, QT_RETHROW, and QT_TRY.

+ Here is the call graph for this function:

Member Function Documentation

◆ acceptDrops()

bool QWidget::acceptDrops ( ) const

Definition at line 3431 of file qwidget.cpp.

References testAttribute(), and Qt::WA_AcceptDrops.

+ Here is the call graph for this function:

◆ actionEvent()

void QWidget::actionEvent ( QActionEvent * event)
protectedvirtual

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

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

Reimplemented in QMenu, QMenuBar, QToolButton, QTornOffMenu, and QToolBar.

Definition at line 9828 of file qwidget.cpp.

Referenced by QToolButton::actionEvent(), and event().

+ Here is the caller graph for this function:

◆ actions()

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

◆ activateWindow()

void QWidget::activateWindow ( )

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(), show()

Definition at line 12873 of file qwidget.cpp.

References window(), and windowHandle().

Referenced by QMdiArea::activatePreviousSubWindow(), QDockWidgetPrivate::endDrag(), EditorWindow::find(), setWindowState(), and showFullScreen().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addAction() [1/7]

QAction * QWidget::addAction ( const QIcon & icon,
const QString & text )

Definition at line 3236 of file qwidget.cpp.

References addAction(), icon, ret, and text.

+ Here is the call graph for this function:

◆ addAction() [2/7]

template<typename... Args, typename = compatible_action_slot_args<Args...>>
QAction * QWidget::addAction ( const QIcon & icon,
const QString & text,
Args &&... args )
inline

Definition at line 581 of file qwidget.h.

References args, connect(), icon, text, and QAction::triggered().

+ Here is the call graph for this function:

◆ addAction() [3/7]

QAction * QWidget::addAction ( const QIcon & icon,
const QString & text,
const QObject * receiver,
const char * member,
Qt::ConnectionType type = Qt::AutoConnection )

Definition at line 3285 of file qwidget.cpp.

References addAction(), QObject::connect(), icon, SIGNAL, and text.

+ Here is the call graph for this function:

◆ addAction() [4/7]

QAction * QWidget::addAction ( const QString & text)

Definition at line 3229 of file qwidget.cpp.

References addAction(), ret, and text.

+ Here is the call graph for this function:

◆ addAction() [5/7]

template<typename... Args, typename = compatible_action_slot_args<Args...>>
QAction * QWidget::addAction ( const QString & text,
Args &&... args )
inline

Definition at line 574 of file qwidget.h.

References args, connect(), text, and QAction::triggered().

+ Here is the call graph for this function:

◆ addAction() [6/7]

QAction * QWidget::addAction ( const QString & text,
const QObject * receiver,
const char * member,
Qt::ConnectionType type = Qt::AutoConnection )

Definition at line 3277 of file qwidget.cpp.

References addAction(), QObject::connect(), SIGNAL, and text.

+ Here is the call graph for this function:

◆ addAction() [7/7]

void QWidget::addAction ( QAction * action)

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

All QWidgets have a list of \l{QAction}s. 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(), QMenu

Definition at line 3117 of file qwidget.cpp.

References insertAction().

Referenced by addAction(), addAction(), addAction(), addAction(), and QToolButton::setDefaultAction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addActions()

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

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

See also
removeAction(), QMenu, addAction()

Definition at line 3127 of file qwidget.cpp.

References actions(), QList< T >::at(), i, insertAction(), and QList< T >::size().

Referenced by QMenu::exec(), and QMenuBarPrivate::updateGeometries().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ adjustSize()

void QWidget::adjustSize ( )

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 \l{QSizePolicy::Expanding} {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(), childrenRect()

Definition at line 8736 of file qwidget.cpp.

References d, ensurePolished(), and resize().

Referenced by QWidgetPrivate::prepareToRender(), QComboBox::setEditable(), setWindowState(), and QComboBoxPrivateContainer::timerEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ autoFillBackground()

bool QWidget::autoFillBackground ( ) const

Definition at line 324 of file qwidget.cpp.

References d.

◆ backgroundRole()

QPalette::ColorRole QWidget::backgroundRole ( ) const

Returns the background role of the widget.

The background role defines the brush from the widget's \l palette that is used to render the background.

If no explicit background role is set, the widget inherits its parent widget's background role.

See also
setBackgroundRole(), foregroundRole()

Definition at line 4360 of file qwidget.cpp.

References QPalette::NoRole, parentWidget(), Qt::SubWindow, and QPalette::Window.

Referenced by QWindows11Style::drawControl(), foregroundRole(), initPainter(), and QWindows11Style::polish().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ backingStore()

QBackingStore * QWidget::backingStore ( ) const
Since
5.0

Returns the QBackingStore this widget will be drawn into.

Definition at line 12284 of file qwidget.cpp.

References QTLWExtra::backingStore, QWidgetRepaintManager::backingStore(), and d.

Referenced by QWindowsVistaStylePrivate::backingStoreForWidget().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ baseSize()

QSize QWidget::baseSize ( ) const

Definition at line 3874 of file qwidget.cpp.

References d.

◆ changeEvent()

void QWidget::changeEvent ( QEvent * event)
protectedvirtual

This event handler can be reimplemented to handle state changes.

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

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, QEvent::ReadOnlyChange.

Reimplemented in QFrame, QLabel, QLineEdit, QMenu, QMenuBar, QRubberBand, QSplitter, QTabBar, QTabWidget, QToolBox, QToolButton, QMdiSubWindow, QErrorMessage, QFileDialog, QAbstractButton, QAbstractSlider, QComboBox, QComboBoxPrivateContainer, QColorDialog, QFontDialog, QMessageBox, QProgressDialog, QAbstractSpinBox, QDialogButtonBox, QDockWidget, QGroupBox, and QToolBar.

Definition at line 9375 of file qwidget.cpp.

References QCoreApplication::closingDown(), d, Qt::Desktop, QGuiApplication::desktopSettingsAware(), QEvent::EnabledChange, QEvent::FontChange, isVisible(), QEvent::MacSizeChange, QEvent::PaletteChange, qApp, QCoreApplication::sendEvent(), QApplication::style(), QEvent::StyleChange, testAttribute(), QEvent::ThemeChange, update(), updateGeometry(), Qt::WA_WState_Polished, and windowType().

Referenced by QFrame::changeEvent(), QLineEdit::changeEvent(), QMenu::changeEvent(), QMenuBar::changeEvent(), QRubberBand::changeEvent(), QTabBar::changeEvent(), QTabWidget::changeEvent(), QMdiSubWindow::changeEvent(), QErrorMessage::changeEvent(), QFileDialog::changeEvent(), QAbstractButton::changeEvent(), QAbstractSlider::changeEvent(), QComboBox::changeEvent(), QColorDialog::changeEvent(), QFontDialog::changeEvent(), QMessageBox::changeEvent(), QProgressDialog::changeEvent(), QAbstractSpinBox::changeEvent(), QDialogButtonBox::changeEvent(), QDockWidget::changeEvent(), QGroupBox::changeEvent(), QToolBar::changeEvent(), and event().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ childAt() [1/2]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the visible child widget at point p in the widget's own coordinate system.

Definition at line 10403 of file qwidget.cpp.

◆ childAt() [2/2]

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

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

Definition at line 798 of file qwidget.h.

Referenced by QToolBar::actionAt(), QDialog::contextMenuEvent(), QMainWindow::contextMenuEvent(), QWidgetWindow::handleEnterLeaveEvent(), QToolBarPrivate::mousePressEvent(), and QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent().

+ Here is the caller graph for this function:

◆ childrenRect()

QRect QWidget::childrenRect ( ) const

Definition at line 3693 of file qwidget.cpp.

References d, i, and qobject_cast< QWidget * >().

+ Here is the call graph for this function:

◆ childrenRegion()

QRegion QWidget::childrenRegion ( ) const

Definition at line 3717 of file qwidget.cpp.

References d, i, qobject_cast< QWidget * >(), and QRegion::translated().

+ Here is the call graph for this function:

◆ clearFocus()

void QWidget::clearFocus ( )

Takes keyboard input focus from the widget.

If the widget has active focus, a \l{focusOutEvent()}{focus out event} is sent to this widget to tell it that it has lost the focus.

This widget must enable focus setting to get the keyboard input focus; that is, it must call setFocusPolicy().

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

Definition at line 6680 of file qwidget.cpp.

References emit, QEvent::FocusAboutToChange, QWidgetWindow::focusObject(), QWindow::focusObjectChanged(), focusWidget(), hasFocus(), QGuiApplication::inputMethod(), Qt::OtherFocusReason, parentWidget(), QCoreApplication::sendEvent(), QApplicationPrivate::setFocusWidget(), testAttribute(), Qt::WA_InputMethodEnabled, window(), and QTLWExtra::window.

Referenced by ~QWidget(), QWidgetWindowPrivate::clearFocusObject(), QWidgetPrivate::reparentFocusWidgets(), QMdiSubWindowPrivate::setActive(), QStackedLayout::setCurrentIndex(), and setParent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearMask()

void QWidget::clearMask ( )

Removes any mask set by setMask().

See also
setMask()

Definition at line 13109 of file qwidget.cpp.

References d, and setMask().

Referenced by QSplitterHandle::resizeEvent(), and QComboBoxPrivateContainer::resizeEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ close

bool QWidget::close ( )
slot

Closes this widget.

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

First it sends the widget a QCloseEvent. The widget is \l{hide()}{hidden} if it \l{QEvent::accept()}{accepts} the close event. If it \l{QEvent::ignore()}{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 \l QGuiApplication::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.

Definition at line 8555 of file qwidget.cpp.

Referenced by QApplicationPrivate::closeAllPopups(), QWidgetPlatformMenu::dismiss(), QMdiSubWindow::eventFilter(), QSplashScreen::finish(), QMenuPrivate::hideMenu(), QTipLabel::hideTipImmediately(), QDockWidgetPrivate::init(), QWhatsThat::keyPressEvent(), QMenu::keyPressEvent(), keyPressEvent(), QMdiSubWindow::mouseDoubleClickEvent(), QWhatsThat::mousePressEvent(), QBalloonTip::mousePressEvent(), mousePressEvent(), QWhatsThat::mouseReleaseEvent(), QProgressDialog::setAutoClose(), QtPrivate::QWellArray::setSelected(), and QBalloonTip::timerEvent().

+ Here is the caller graph for this function:

◆ closeEvent()

void QWidget::closeEvent ( QCloseEvent * event)
protectedvirtual

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 \l{QEvent::}{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.

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

Reimplemented in QDialog, QAlphaWidget, QRollEffect, QMdiSubWindow, MainWindow, QMessageBox, QProgressDialog, QAbstractSpinBox, and QDockWidget.

Definition at line 9849 of file qwidget.cpp.

Referenced by QAlphaWidget::closeEvent(), QRollEffect::closeEvent(), QAbstractSpinBox::closeEvent(), and event().

+ Here is the caller graph for this function:

◆ contentsMargins()

QMargins QWidget::contentsMargins ( ) const

The contentsMargins function returns the widget's contents margins.

Since
4.6
See also
setContentsMargins(), contentsRect()

Definition at line 7651 of file qwidget.cpp.

References d, testAttribute(), and Qt::WA_ContentsMarginsRespectsSafeArea.

Referenced by contentsRect(), QCalendarWidget::minimumSizeHint(), and QComboBox::showPopup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ contentsRect()

QRect QWidget::contentsRect ( ) const

Returns the area inside the widget's margins.

See also
setContentsMargins(), contentsMargins()

Definition at line 7664 of file qwidget.cpp.

References contentsMargins(), and rect.

Referenced by QSplitterHandle::closestLegalPosition(), QFrame::frameRect(), QLineEdit::initStyleOption(), QtPrivate::QColorPicker::mouseMoveEvent(), QtPrivate::QColorPicker::mousePressEvent(), QtPrivate::QColorPicker::paintEvent(), QLabel::paintEvent(), QSplitterHandle::paintEvent(), QSplitterHandle::resizeEvent(), QtPrivate::QColorPicker::setCol(), QSplitter::setRubberBand(), and QLabel::setScaledContents().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ contextMenuEvent()

void QWidget::contextMenuEvent ( QContextMenuEvent * event)
protectedvirtual

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 \l contextMenuPolicy is Qt::DefaultContextMenu.

The default implementation ignores the context event. See the \l QContextMenuEvent documentation for more details.

See also
event(), QContextMenuEvent, customContextMenuRequested()

Reimplemented in QDialog, QLineEdit, QScrollBar, QMdiSubWindow, QComboBox, QLabel, and QMainWindow.

Definition at line 9868 of file qwidget.cpp.

Referenced by QScrollBar::contextMenuEvent(), and event().

+ Here is the caller graph for this function:

◆ contextMenuPolicy()

Qt::ContextMenuPolicy QWidget::contextMenuPolicy ( ) const

Definition at line 7778 of file qwidget.cpp.

◆ create()

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

Creates a new widget window.

The parameters window, initializeWindow, and destroyOldWindow are ignored in Qt 5. Please use QWindow::fromWinId() to create a QWindow wrapping a foreign window and pass it to QWidget::createWindowContainer() instead.

See also
createWindowContainer(), QWindow::fromWinId()

Definition at line 1156 of file qwidget.cpp.

References Qt::AA_NativeWindows, d, Qt::Desktop, internalWinId(), isWindow(), QObject::parent(), parentWidget(), Q_ASSERT, Q_UNLIKELY, Q_UNUSED, qEnvironmentVariableIntValue(), qWarning, QWidgetRepaintManager, setAttribute(), Qt::SubWindow, testAttribute(), QCoreApplicationPrivate::testAttribute(), Qt::WA_DontCreateNativeAncestors, Qt::WA_DropSiteRegistered, Qt::WA_NativeWindow, Qt::WA_PaintOnScreen, Qt::WA_SetWindowIcon, Qt::WA_WState_Created, Qt::Widget, Qt::Window, window(), and windowType().

Referenced by QWidgetPrivate::create(), QQuickLabsPlatformMenuBar::insertMenu(), QWidgetPrivate::setVisible(), and QComboBox::showPopup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createWindowContainer()

QWidget * QWidget::createWindowContainer ( QWindow * window,
QWidget * parent = nullptr,
Qt::WindowFlags flags = Qt::WindowFlags() )
static

Creates a QWidget that makes it possible to embed window into a QWidget-based application.

The window container is created as a child of parent and with window flags flags.

Once the window has been embedded into the container, the container will control the window's geometry and visibility. Explicit calls to QWindow::setGeometry(), QWindow::show() or QWindow::hide() on an embedded window is not recommended.

The container takes over ownership of window. The window can be removed from the window container with a call to QWindow::setParent().

The window container is attached as a native child window to the toplevel window it is a child of. When a window container is used as a child of a QAbstractScrollArea or QMdiArea, it will create a \l {Native Widgets vs Alien Widgets} {native window} for every widget in its parent chain to allow for proper stacking and clipping in this use case. Creating a native window for the window container also allows for proper stacking and clipping. This must be done before showing the window container. Applications with many native child windows may suffer from performance issues.

The window container has a number of known limitations:

\list

  • Stacking order; The embedded window will stack on top of the widget hierarchy as an opaque box. The stacking order of multiple overlapping window container instances is undefined.
  • Focus Handling; It is possible to let the window container instance have any focus policy and it will delegate focus to the window via a call to QWindow::requestActivate(). However, returning to the normal focus chain from the QWindow instance will be up to the QWindow instance implementation itself. For instance, when entering a Qt Quick based window with tab focus, it is quite likely that further tab presses will only cycle inside the QML application. Also, whether QWindow::requestActivate() actually gives the window focus, is platform dependent.
  • Using many window container instances in a QWidget-based application can greatly hurt the overall performance of the application.
  • Since 6.7, if window belongs to a widget (that is, window was received from calling \l windowHandle()), no container will be created. Instead, this function will return the widget itself, after being reparented to \l parent. Since no container will be created, flags will be ignored. In other words, if window belongs to a widget, consider just reparenting that widget to parent instead of using this function.

\endlist

Definition at line 178 of file qwindowcontainer.cpp.

References QObject::parent(), qWarning, setParent(), widget, and window().

+ Here is the call graph for this function:

◆ createWinId()

void QWidget::createWinId ( )

Ensures that the widget has a window system identifier, i.e. that it is known to the windowing system.

Definition at line 2441 of file qwidget.cpp.

References d.

Referenced by setAttribute(), QWidgetPlatformDialog::show(), and QWidgetPlatformMenu::showPopup().

+ Here is the caller graph for this function:

◆ cursor()

QCursor QWidget::cursor ( ) const

Definition at line 4948 of file qwidget.cpp.

References Qt::ArrowCursor, cursor, d, isWindow(), parentWidget(), testAttribute(), and Qt::WA_SetCursor.

+ Here is the call graph for this function:

◆ customContextMenuRequested

void QWidget::customContextMenuRequested ( const QPoint & pos)
signal

This signal is emitted when the widget's \l 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 \l{QAbstractScrollArea::viewport()}{viewport()}.

See also
mapToGlobal(), QMenu, contextMenuPolicy

Referenced by event().

+ Here is the caller graph for this function:

◆ destroy()

void QWidget::destroy ( bool destroyWindow = true,
bool destroySubWindows = true )
protected

Frees up window system resources.

Destroys the widget window if destroyWindow is true.

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

This function is usually called from the QWidget destructor.

Definition at line 12451 of file qwidget.cpp.

References QObject::children(), d, Qt::Desktop, destroy(), geometry, i, isWindow(), keyboardGrabber(), mouseGrabber(), parentWidget(), Qt::Popup, qApp, qobject_cast< QWidget * >(), releaseKeyboard(), releaseMouse(), QApplicationPrivate::setActiveWindow(), setAttribute(), testAttribute(), Qt::WA_NativeWindow, Qt::WA_WState_Created, widget, windowHandle(), and windowType().

Referenced by ~QWidget(), destroy(), and event().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ devType()

int QWidget::devType ( ) const
overridevirtual

Reimplemented from QPaintDevice.

Definition at line 882 of file qwidget.cpp.

References QInternal::Widget.

◆ effectiveWinId()

WId QWidget::effectiveWinId ( ) const
Since
4.4

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.
See also
nativeParentWidget()

Definition at line 2462 of file qwidget.cpp.

References internalWinId(), nativeParentWidget(), testAttribute(), and Qt::WA_WState_Created.

Referenced by QApplicationPrivate::dispatchEnterLeave().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ensurePolished()

void QWidget::ensurePolished ( ) const

Ensures that the widget and its children have been polished by QStyle (i.e., have 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()

Definition at line 10153 of file qwidget.cpp.

References QList< T >::at(), QEvent::ChildPolished, QObject::children(), d, i, metaObject(), o, QEvent::Polish, QCoreApplication::sendEvent(), and QList< T >::size().

Referenced by QTipLabel::QTipLabel(), QWhatsThat::QWhatsThat(), adjustSize(), event(), QMdiSubWindow::event(), QAbstractSpinBox::minimumSizeHint(), QCalendarWidget::minimumSizeHint(), QLabel::minimumSizeHint(), QLineEdit::minimumSizeHint(), QMdiSubWindow::minimumSizeHint(), QMenuBar::minimumSizeHint(), QSplitter::minimumSizeHint(), QWidgetPrivate::prepareToRender(), showFullScreen(), showMaximized(), showMinimized(), showNormal(), QtPrivate::QWellArray::sizeHint(), DetailButton::sizeHint(), QAbstractSpinBox::sizeHint(), QCheckBox::sizeHint(), QDateTimeEdit::sizeHint(), QDockWidgetTitleButton::sizeHint(), QLineEdit::sizeHint(), QMdi::ControllerWidget::sizeHint(), QMenuBar::sizeHint(), QProgressBar::sizeHint(), QPushButton::sizeHint(), QRadioButton::sizeHint(), QScrollBar::sizeHint(), QSlider::sizeHint(), QSplitter::sizeHint(), QToolButton::sizeHint(), QSplitter::sizes(), and QComboBoxPrivate::updateViewContainerPaletteAndOpacity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ enterEvent()

void QWidget::enterEvent ( QEnterEvent * event)
protectedvirtual

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(), event()

Reimplemented in QComboBoxPrivateScroller, QMenu, QToolButton, and QDockWidgetTitleButton.

Definition at line 9708 of file qwidget.cpp.

Referenced by QToolButton::enterEvent(), QDockWidgetTitleButton::enterEvent(), QQuickWidget::event(), and event().

+ Here is the caller graph for this function:

◆ event()

bool QWidget::event ( QEvent * event)
overrideprotectedvirtual

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 \l 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 \l 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(), QObject::timerEvent()

Reimplemented from QObject.

Reimplemented in QWindowContainer, QWizard, and Window.

Definition at line 8859 of file qwidget.cpp.

References QEvent::accept(), QEvent::ActionAdded, QEvent::ActionChanged, actionEvent(), QEvent::ActionRemoved, Qt::ActionsContextMenu, QEvent::ActivationChange, QPalette::Active, QApplication::activeModalWidget(), Qt::AltModifier, QEvent::ApplicationFontChange, QEvent::ApplicationLayoutDirectionChange, QEvent::ApplicationPaletteChange, QEvent::ApplicationWindowIconChange, QByteArray::at(), changeEvent(), QEvent::Close, closeEvent(), QByteArray::constData(), QEvent::ContentsRectChange, QEvent::ContextMenu, contextMenuEvent(), Qt::ControlModifier, create(), Qt::CustomContextMenu, customContextMenuRequested(), d, Qt::DefaultContextMenu, Qt::Desktop, destroy(), QEvent::DevicePixelRatioChange, QWidgetPrivate::DirectionEast, QWidgetPrivate::DirectionNorth, QWidgetPrivate::DirectionSouth, QWidgetPrivate::DirectionWest, QEvent::DragEnter, QEvent::DragLeave, QEvent::DragMove, QEvent::Drop, QEvent::DynamicPropertyChange, QEvent::EmbeddingControl, emit, QEvent::EnabledChange, ensurePolished(), QEvent::Enter, enterEvent(), QObject::event(), QMenu::exec(), QEvent::FocusIn, focusInEvent(), focusNextPrevChild(), QEvent::FocusOut, focusOutEvent(), QApplication::font(), QEvent::FontChange, QEvent::Gesture, QContextMenuEvent::globalPos(), QHelpEvent::globalPos(), QEvent::Hide, hideEvent(), QEvent::HoverEnter, QEvent::HoverLeave, i, QEvent::IconTextChange, Qt::ImCursorRectangle, Qt::ImEnabled, QPalette::Inactive, QEvent::InputMethod, inputMethodEvent(), QEvent::InputMethodQuery, inputMethodQuery(), QEvent::isAccepted(), isEnabled(), isEqual(), isHidden(), isMinimized(), isVisible(), isWindow(), QKeyEvent::key(), Qt::Key_Backtab, Qt::Key_Down, Qt::Key_F1, Qt::Key_Left, Qt::Key_Right, Qt::Key_Tab, Qt::Key_Up, QEvent::KeyboardLayoutChange, QEvent::KeyPress, keyPressEvent(), QEvent::KeyRelease, keyReleaseEvent(), QEvent::LanguageChange, QEvent::LayoutDirectionChange, QEvent::Leave, leaveEvent(), QEvent::LocaleChange, QPaintDevice::logicalDpiY(), QEvent::MacSizeChange, mapToGlobal(), QEvent::ModifiedChange, QKeyEvent::modifiers(), QEvent::MouseButtonDblClick, QEvent::MouseButtonPress, QEvent::MouseButtonRelease, mouseDoubleClickEvent(), QEvent::MouseMove, mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), QEvent::MouseTrackingChange, QEvent::Move, moveEvent(), Qt::NavigationModeKeypadDirectional, Qt::NavigationModeKeypadTabOrder, Qt::NoButton, o, QEvent::Paint, paintEvent(), QGuiApplication::palette(), QApplication::palette(), palette, QEvent::PaletteChange, QEvent::ParentChange, QEvent::PlatformSurface, QEvent::Polish, QStyle::polish(), QEvent::PolishRequest, pos, Qt::PreventContextMenu, property, Q_FALLTHROUGH, qobject_cast< QWidget * >(), qstrncmp(), QInputMethodQueryEvent::queries(), QEvent::QueryWhatsThis, QEvent::ReadOnlyChange, QEvent::Resize, resizeEvent(), QEvent::ScreenChangeInternal, QCoreApplication::sendEvent(), setAttribute(), QObject::setProperty(), Qt::ShiftModifier, QEvent::ShortcutOverride, QEvent::Show, showEvent(), QWhatsThis::showText(), QToolTip::showText(), QEvent::ShowWindowRequest, QByteArray::size(), style(), QEvent::StyleAnimationUpdate, QEvent::StyleChange, QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed, QPlatformSurfaceEvent::SurfaceCreated, QEvent::TabletMove, QEvent::TabletPress, QEvent::TabletRelease, QEvent::TabletTrackingChange, testAttribute(), QEvent::ThemeChange, QEvent::ToolBarChange, QEvent::ToolTip, QEvent::TouchBegin, QEvent::TouchCancel, QEvent::TouchEnd, QEvent::TouchUpdate, update(), QEvent::UpdateLater, QEvent::UpdateRequest, Qt::WA_InputMethodEnabled, Qt::WA_SetWindowIcon, Qt::WA_TabletTracking, Qt::WA_WState_Created, Qt::WA_WState_Polished, QEvent::WhatsThis, QEvent::Wheel, widget, win, window(), QEvent::WindowActivate, QEvent::WindowBlocked, QEvent::WindowDeactivate, windowHandle(), Qt::WindowMinimized, QEvent::WindowStateChange, QEvent::WindowTitleChange, windowType(), QEvent::WindowUnblocked, and winId().

Referenced by QSystemTrayIconSys::event(), QKeySequenceEdit::event(), QLineEdit::event(), QMenu::event(), QMenuBar::event(), QSizeGrip::event(), QSplitterHandle::event(), QStatusBar::event(), QTabBar::event(), QTabWidget::event(), QQuickWidget::event(), QOpenGLWidget::event(), QRhiWidget::event(), QAbstractButton::event(), QAbstractSlider::event(), QCalendarPopup::event(), QFocusFrame::event(), QFrame::event(), QProgressBar::event(), QRubberBand::event(), QSplashScreen::event(), MyClass::event(), QWindowContainer::event(), MyWidget::event(), Window::event(), QAbstractSpinBox::event(), QCalendarWidget::event(), QComboBox::event(), QDialogButtonBox::event(), QDockWidget::event(), QGroupBox::event(), QMainWindow::event(), QMdi::ControlLabel::event(), QMdi::ControllerWidget::event(), QMdiSubWindow::event(), QToolBar::event(), and QVideoWidget::event().

+ Here is the caller graph for this function:

◆ find()

QWidget * QWidget::find ( WId id)
static

Returns a pointer to the widget with window identifier/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, \nullptr is returned.

Definition at line 2327 of file qwidget.cpp.

References QWidgetPrivate::mapper.

◆ focusInEvent()

void QWidget::focusInEvent ( QFocusEvent * event)
protectedvirtual

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 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(), QFocusEvent

Reimplemented in QtPrivate::QWellArray, QLineEdit, QMenuBar, QPushButton, QAbstractButton, QComboBox, QLabel, QAbstractSpinBox, QDateTimeEdit, QGroupBox, QQuickWidget, and QMdiSubWindow.

Definition at line 9658 of file qwidget.cpp.

References focusPolicy, isWindow(), Qt::NoFocus, and update().

Referenced by event(), QAbstractButton::focusInEvent(), QLabel::focusInEvent(), QAbstractSpinBox::focusInEvent(), and QGroupBox::focusInEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ focusNextChild()

bool QWidget::focusNextChild ( )
inlineprotected

Finds a new widget to give the keyboard focus to, as appropriate for \uicontrol Tab, and returns true if it can find a new widget, or false if it can't.

See also
focusPreviousChild()

Definition at line 727 of file qwidget.h.

◆ focusNextPrevChild()

bool QWidget::focusNextPrevChild ( bool next)
protectedvirtual

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(), focusPreviousChild()

Reimplemented in QDateTimeEdit, QLabel, QMenu, and QQuickWidget.

Definition at line 6774 of file qwidget.cpp.

References Qt::BacktabFocusReason, d, QEvent::FocusIn, QApplicationPrivate::focusNextPrevChild_helper(), isWindow(), next, parentWidget(), qt_window_private(), Qt::SubWindow, Qt::TabFocusReason, window(), windowHandle(), and windowType().

Referenced by event(), QDateTimeEdit::focusNextPrevChild(), QLabel::focusNextPrevChild(), QScrollArea::focusNextPrevChild(), and QAbstractButton::keyPressEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ focusOutEvent()

void QWidget::focusOutEvent ( QFocusEvent * event)
protectedvirtual

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 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(), QFocusEvent

Reimplemented in QtPrivate::QWellArray, QKeySequenceEdit, QLineEdit, QMenuBar, QPushButton, QAbstractButton, QComboBox, QLabel, QAbstractSpinBox, QQuickWidget, and QMdiSubWindow.

Definition at line 9684 of file qwidget.cpp.

References focusPolicy, QGuiApplication::inputMethod(), isWindow(), Qt::NoFocus, qApp, testAttribute(), update(), and Qt::WA_InputMethodEnabled.

Referenced by event(), QKeySequenceEdit::focusOutEvent(), QLineEdit::focusOutEvent(), QAbstractButton::focusOutEvent(), QLabel::focusOutEvent(), and QAbstractSpinBox::focusOutEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ focusPolicy()

Qt::FocusPolicy QWidget::focusPolicy ( ) const

Definition at line 7810 of file qwidget.cpp.

◆ focusPreviousChild()

bool QWidget::focusPreviousChild ( )
inlineprotected

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

See also
focusNextChild()

Definition at line 728 of file qwidget.h.

◆ focusProxy()

QWidget * QWidget::focusProxy ( ) const

Returns the focus proxy, or \nullptr if there is no focus proxy.

See also
setFocusProxy()

Definition at line 6424 of file qwidget.cpp.

References d.

Referenced by correctWidgetContext(), QWidgetPrivate::deepestFocusProxy(), QAbstractItemViewPrivate::selectAllInEditor(), setFocus(), and setTabOrder().

+ Here is the caller graph for this function:

◆ focusWidget()

◆ font()

const QFont & QWidget::font ( ) const
inline

Definition at line 844 of file qwidget.h.

◆ fontInfo()

QFontInfo QWidget::fontInfo ( ) const
inline

Returns the font info for the widget's current font.

Equivalent to QFontInfo(widget->font()).

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

Definition at line 850 of file qwidget.h.

◆ fontMetrics()

◆ foregroundRole()

QPalette::ColorRole QWidget::foregroundRole ( ) const

Returns the foreground role.

The foreground role defines the color from the widget's \l 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(), backgroundRole()

Definition at line 4411 of file qwidget.cpp.

References backgroundRole(), QPalette::Base, QPalette::Button, QPalette::ButtonText, d, QPalette::Dark, QPalette::Highlight, QPalette::HighlightedText, QPalette::Light, QPalette::NoRole, QPalette::Shadow, QPalette::Text, QPalette::ToolTipBase, QPalette::ToolTipText, and QPalette::WindowText.

Referenced by QCommonStyle::drawControl(), initPainter(), and QLabel::paintEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ frameGeometry()

QRect QWidget::frameGeometry ( ) const

Definition at line 3468 of file qwidget.cpp.

References QRect::bottom(), d, isWindow(), QRect::left(), Qt::Popup, QRect::right(), QRect::top(), and windowType().

+ Here is the call graph for this function:

◆ frameSize()

QSize QWidget::frameSize ( ) const

Definition at line 7090 of file qwidget.cpp.

References QRect::bottom(), d, isWindow(), QRect::left(), Qt::Popup, QRect::right(), QRect::top(), and windowType().

+ Here is the call graph for this function:

◆ geometry()

const QRect & QWidget::geometry ( ) const
inline

Definition at line 892 of file qwidget.h.

◆ grab()

QPixmap QWidget::grab ( const QRect & rectangle = QRect(QPoint(0, 0), QSize(-1, -1)))
Since
5.0

Renders the widget into a pixmap restricted by the given rectangle. If the widget has any children, then they are also painted in the appropriate positions.

If a rectangle with an invalid size is specified (the default), the entire widget is painted.

See also
render(), QPixmap

Definition at line 5212 of file qwidget.cpp.

References d, QPaintDevice::devicePixelRatio(), dpr(), DrawChildren, DrawWindowBackground, IgnoreMask, QPixmap, rect, sendResizeEvents(), testAttribute(), QRect::topLeft(), Qt::transparent, Qt::WA_PendingResizeEvent, and Qt::WA_WState_Created.

Referenced by QRollEffect::QRollEffect(), and QAlphaWidget::run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ grabGesture()

void QWidget::grabGesture ( Qt::GestureType gesture,
Qt::GestureFlags flags = Qt::GestureFlags() )

Subscribes the widget to a given gesture with specific flags.

See also
ungrabGesture(), QGestureEvent
Since
4.6

Definition at line 12414 of file qwidget.cpp.

References d, QGestureManager::instance(), and void.

Referenced by QScroller::grabGesture(), and QGraphicsView::setupViewport().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ grabKeyboard()

void QWidget::grabKeyboard ( )

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(), focusWidget()

Definition at line 12783 of file qwidget.cpp.

References grabberWindow(), keyboardGrb, and window().

Referenced by QWidgetResizeHandler::doResize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ grabMouse() [1/2]

void QWidget::grabMouse ( )

Grabs the mouse input.

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

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

It is seldom 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().
On Windows, grabMouse() only works when the mouse is inside a window owned by the process. On \macos, grabMouse() only works when the mouse is inside the frame of that widget.
See also
releaseMouse(), grabKeyboard(), releaseKeyboard()

Definition at line 12715 of file qwidget.cpp.

References grabMouseForWidget().

Referenced by QWidgetResizeHandler::doResize(), and QWidgetResizeHandler::keyPressEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ grabMouse() [2/2]

void QWidget::grabMouse ( const QCursor & cursor)

Definition at line 12737 of file qwidget.cpp.

References cursor, and grabMouseForWidget().

+ Here is the call graph for this function:

◆ grabShortcut()

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

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 \l{QAction}s with the shortcut key sequences you require (if you also want equivalent menu options and toolbar buttons), or create \l{QShortcut}s 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(), setShortcutEnabled()

Definition at line 11806 of file qwidget.cpp.

References context, QGuiApplicationPrivate::instance(), Q_ASSERT, qApp, qWidgetShortcutContextMatcher(), setAttribute(), and Qt::WA_GrabbedShortcut.

Referenced by QTabBar::insertTab(), QAbstractButton::setShortcut(), QTabBar::setTabText(), and QGroupBox::setTitle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasFocus()

bool QWidget::hasFocus ( ) const

Definition at line 6443 of file qwidget.cpp.

References QApplication::focusWidget(), focusWidget(), and window().

Referenced by QFileDialogPrivate::autoCompleteFileName(), clearFocus(), QLineEdit::event(), QStyleOption::initFrom(), QComboBox::initStyleOption(), QMenuBar::initStyleOption(), QLineEdit::inputMethodEvent(), QAbstractButton::keyPressEvent(), QMenuBar::leaveEvent(), QtPrivate::QWellArray::paintCell(), QMdiSubWindowPrivate::restoreFocus(), QFileDialogPrivate::selectionChanged(), QTabBar::setCurrentIndex(), QDialogPrivate::setVisible(), QMdiSubWindow::showShaded(), and QFontDialogPrivate::sizeHighlighted().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasHeightForWidth()

bool QWidget::hasHeightForWidth ( ) const
virtual
Since
5.0

Returns true if the widget's preferred height depends on its width; otherwise returns false.

Reimplemented in QTabWidget.

Definition at line 10382 of file qwidget.cpp.

References d.

Referenced by QWidgetWindowPrivate::closestAcceptableGeometry(), QWidgetItem::hasHeightForWidth(), heightForWidth(), and QSizeGrip::mousePressEvent().

+ Here is the caller graph for this function:

◆ hasMouseTracking()

bool QWidget::hasMouseTracking ( ) const
inline

Definition at line 856 of file qwidget.h.

References Qt::WA_MouseTracking.

Referenced by QPushButton::initStyleOption().

+ Here is the caller graph for this function:

◆ hasTabletTracking()

bool QWidget::hasTabletTracking ( ) const
inline

Definition at line 865 of file qwidget.h.

References Qt::WA_TabletTracking.

◆ height()

int QWidget::height ( ) const
inline

Definition at line 901 of file qwidget.h.

◆ heightForWidth()

int QWidget::heightForWidth ( int w) const
virtual

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.

Reimplemented in QTabWidget, QCommandLinkButton, QLabel, and QMenuBar.

Definition at line 10369 of file qwidget.cpp.

References hasHeightForWidth(), layout(), and QLayout::totalHeightForWidth().

Referenced by QWidgetItem::heightForWidth(), QLabel::heightForWidth(), menuBarHeightForWidth(), QWidgetItem::minimumHeightForWidth(), and QScrollAreaPrivate::updateScrollBars().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hide

void QWidget::hide ( )
slot

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(), close()

Definition at line 8128 of file qwidget.cpp.

References setVisible().

Referenced by QtPrivate::QColorShower::QColorShower(), QToolBarLayout::QToolBarLayout(), QDialog::~QDialog(), QPrintDialog::~QPrintDialog(), ~QWidget(), QCalendarWidgetPrivate::_q_yearClicked(), QCalendarWidgetPrivate::_q_yearEditingFinished(), QCalendarWidgetPrivate::createNavigationBar(), QWidgetAction::deleteWidget(), QWizardPrivate::disableUpdates(), QComboBoxPrivate::doHidePopup(), QWizardPrivate::ensureButton(), QInputDialogPrivate::ensureComboBox(), QInputDialogPrivate::ensureDoubleSpinBox(), QInputDialogPrivate::ensureIntSpinBox(), QInputDialogPrivate::ensureLineEdit(), QFocusFrame::eventFilter(), QWidgetPlatformColorDialog::hide(), QWidgetPlatformFileDialog::hide(), QWidgetPlatformFontDialog::hide(), QWidgetPlatformMessageDialog::hide(), QMenuBarPrivate::init(), QTabBarPrivate::init(), QStatusBar::insertWidget(), QDialogButtonBoxPrivate::layoutButtons(), QTabBarPrivate::layoutTabs(), QMenuBar::mousePressEvent(), QSplashScreen::mousePressEvent(), QStatusBar::removeWidget(), QAlphaWidget::render(), QSplitter::replaceWidget(), QProgressDialog::reset(), QDockAreaLayoutInfo::restoreState(), QTabBar::setAutoHide(), QWizardPrivate::setButtonLayout(), QTabWidget::setCornerWidget(), QMenuBarPrivate::setCurrentAction(), QStackedLayout::setCurrentIndex(), QToolBarLayout::setGeometry(), QInputDialogPrivate::setInputWidget(), setParent(), QWatermarkLabel::setSideWidget(), QTabBar::setTabButton(), QFocusFrame::setWidget(), QDockWidgetLayout::setWidgetForRole(), QComboBox::showPopup(), and QMenuBarPrivate::updateGeometries().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hideEvent()

void QWidget::hideEvent ( QHideEvent * event)
protectedvirtual

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(), QHideEvent

Reimplemented in QComboBoxPrivateScroller, QCalendarPopup, QMenu, QScrollBar, QTabBar, QQuickWidget, QComboBox, QComboBoxPrivateContainer, QAbstractSpinBox, QVideoWidget, QMdiSubWindow, and QSizeGrip.

Definition at line 10091 of file qwidget.cpp.

Referenced by event(), QAbstractSpinBox::hideEvent(), QVideoWidget::hideEvent(), and QSizeGrip::hideEvent().

+ Here is the caller graph for this function:

◆ initPainter()

void QWidget::initPainter ( QPainter * painter) const
overrideprotectedvirtual

Initializes the painter pen, background and font to the same as the given widget's.

This function is called automatically when the painter is opened on a QWidget.

Reimplemented from QPaintDevice.

Definition at line 12950 of file qwidget.cpp.

References backgroundRole(), QPalette::brush(), QPainter::font(), font, foregroundRole(), painter, palette, and QPainter::pen().

+ Here is the call graph for this function:

◆ inputMethodEvent()

void QWidget::inputMethodEvent ( QInputMethodEvent * event)
protectedvirtual

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 \l QInputMethodEvent documentation for more details.

See also
event(), QInputMethodEvent

Reimplemented in QComboBox, and QLineEdit.

Definition at line 9891 of file qwidget.cpp.

Referenced by event().

+ Here is the caller graph for this function:

◆ inputMethodHints()

Qt::InputMethodHints QWidget::inputMethodHints ( ) const

Definition at line 9950 of file qwidget.cpp.

References Qt::ImhNone, priv(), and Q_ASSERT.

+ Here is the call graph for this function:

◆ inputMethodQuery()

QVariant QWidget::inputMethodQuery ( Qt::InputMethodQuery query) const
virtual

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, QInputMethodQueryEvent, inputMethodHints

Reimplemented in QAbstractSpinBox, QComboBox, and QLineEdit.

Definition at line 9906 of file qwidget.cpp.

References font, height, Qt::ImAnchorPosition, Qt::ImCursorPosition, Qt::ImCursorRectangle, Qt::ImFont, Qt::ImHints, Qt::ImInputItemClipRectangle, inputMethodHints, inputMethodQuery(), and width.

Referenced by QScrollArea::ensureWidgetVisible(), event(), QWidgetWindow::handleContextMenuEvent(), QLineEdit::inputMethodQuery(), QComboBox::inputMethodQuery(), QPlainTextEdit::inputMethodQuery(), QTextEdit::inputMethodQuery(), inputMethodQuery(), and QComboBox::inputMethodQuery().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insertAction()

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

Inserts the action action to this widget's list of actions, before the action before.

It appends the action if before is \nullptr 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, actions()

Definition at line 3142 of file qwidget.cpp.

References QEvent::ActionAdded, QList< T >::append(), QAction::associatedObjects(), d, pos, Q_UNLIKELY, qWarning, removeAction(), and QCoreApplication::sendEvent().

Referenced by addAction(), addActions(), insertActions(), QMenu::insertMenu(), QMenuBar::insertMenu(), QWidgetPlatformMenu::insertMenuItem(), QMenu::insertSection(), QMenu::insertSection(), QMenu::insertSeparator(), QMenuBar::insertSeparator(), QToolBar::insertSeparator(), QToolBar::insertWidget(), and QTornOffMenu::syncWithMenu().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insertActions()

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

Inserts the actions actions to this widget's list of actions, before the action before.

It appends the action if before is \nullptr 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(), contextMenuPolicy

Definition at line 3176 of file qwidget.cpp.

References actions(), QList< T >::at(), i, insertAction(), and QList< T >::size().

+ Here is the call graph for this function:

◆ internalWinId()

WId QWidget::internalWinId ( ) const
inline

Returns the window system identifier of the widget, or 0 if the widget is not created yet.

Definition at line 220 of file qwidget.h.

Referenced by ~QWidget(), create(), effectiveWinId(), QWidgetPrivate::hideChildren(), operator<<(), q_createNativeChildrenAndSetParent(), QApplicationPrivate::sendMouseEvent(), setAttribute(), and winId().

+ Here is the caller graph for this function:

◆ isActiveWindow()

bool QWidget::isActiveWindow ( ) const

Definition at line 6877 of file qwidget.cpp.

References QApplication::activeWindow(), QGuiApplication::focusWindow(), isActiveWindow, isModal(), isVisible(), parentWidget(), Qt::Popup, QStyle::SH_Widget_ShareActivation, style(), Qt::Tool, window(), windowHandle(), and windowType().

+ Here is the call graph for this function:

◆ isAncestorOf()

bool QWidget::isAncestorOf ( const QWidget * child) const

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.

Definition at line 8815 of file qwidget.cpp.

References child.

Referenced by QWidgetPrivate::determineLastFocusChild(), QApplicationPrivate::focusNextPrevChild_helper(), iWantTheFocus(), QApplicationPrivate::sendSyntheticEnterLeave(), QMdiSubWindowPrivate::setActive(), QStackedLayout::setCurrentIndex(), setFocusProxy(), QMdiSubWindowPrivate::setFocusWidget(), QComboBoxPrivateContainer::setItemView(), setParent(), setTabOrder(), QMdiSubWindow::showShaded(), QWidgetRepaintManager::staticContents(), QGraphicsProxyWidget::subWidgetRect(), and QApplicationPrivate::translateRawTouchEvent().

+ Here is the caller graph for this function:

◆ isEnabled()

◆ isEnabledTo()

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

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

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

isEnabledTo(0) returns false if this widget or any if its ancestors was explicitly disabled.

The word ancestor here means a parent widget within the same window.

Therefore isEnabledTo(0) stops at this widget's window, unlike isEnabled() which also takes parent windows into considerations.

See also
setEnabled(), enabled

Definition at line 3090 of file qwidget.cpp.

References parentWidget(), testAttribute(), and Qt::WA_ForceDisabled.

+ Here is the call graph for this function:

◆ isFullScreen()

bool QWidget::isFullScreen ( ) const

Definition at line 2982 of file qwidget.cpp.

References Qt::WindowFullScreen.

Referenced by normalGeometry(), QVideoWidget::setFullScreen(), and snippet_ctor2().

+ Here is the caller graph for this function:

◆ isHidden()

bool QWidget::isHidden ( ) const
inline

Returns true if the widget is hidden, otherwise returns false.

A hidden widget will only become visible when show() is called on it. It will not be automatically shown when the parent is shown.

To check visibility, use !isVisible() instead (notice the exclamation mark).

isHidden() implies !isVisible(), but a widget can be not visible and not hidden at the same time. This is the case for widgets that are children of widgets that are not visible.

Widgets are hidden if: \list

  • they were created as independent windows,
  • they were created as children of visible widgets,
  • hide() or setVisible(false) was called. \endlist

Definition at line 877 of file qwidget.h.

References Qt::WA_WState_Hidden.

Referenced by QMdiSubWindowPrivate::drawTitleBarWhenMaximized(), QOpenGLWidget::event(), event(), QToolBar::event(), QWidgetItem::isEmpty(), QFormLayoutItem::isHidden(), QFormLayout::isRowVisible(), isVisibleTo(), menuBarHeightForWidth(), QAbstractButtonPrivate::moveFocus(), QTabBarPrivate::normalizedScrollRect(), QWidgetPrivate::prepareToRender(), QSplitterPrivate::recalc(), QSplitter::replaceWidget(), QToolBarAreaLayout::saveState(), setFocus(), QToolBarLayout::setGeometry(), showAllHiddenTopLevelWidgets(), and waitForPopup().

+ Here is the caller graph for this function:

◆ isLeftToRight()

bool QWidget::isLeftToRight ( ) const
inline

Definition at line 420 of file qwidget.h.

References Qt::LeftToRight.

Referenced by QMdiSubWindow::eventFilter(), QMdiSubWindow::keyPressEvent(), and QMdiSubWindow::resizeEvent().

+ Here is the caller graph for this function:

◆ isMaximized()

bool QWidget::isMaximized ( ) const

◆ isMinimized()

bool QWidget::isMinimized ( ) const

Definition at line 2836 of file qwidget.cpp.

References Qt::WindowMinimized.

Referenced by event(), QMdiSubWindow::event(), QMdiSubWindow::minimumSizeHint(), QMdiSubWindow::mouseDoubleClickEvent(), QWidgetResizeHandler::mouseMoveEvent(), QMdiSubWindow::paintEvent(), QMdiSubWindow::showEvent(), and showMinimized().

+ Here is the caller graph for this function:

◆ isModal()

bool QWidget::isModal ( ) const
inline

Definition at line 817 of file qwidget.h.

References Qt::NonModal.

Referenced by QDialog::closeEvent(), isActiveWindow(), and QProgressDialog::setValue().

+ Here is the caller graph for this function:

◆ isRightToLeft()

◆ isVisible()

bool QWidget::isVisible ( ) const
inline

Definition at line 874 of file qwidget.h.

References Qt::WA_WState_Visible.

Referenced by ~QWidget(), QMenu::actionEvent(), QMenuBar::actionEvent(), QDialog::adjustPosition(), changeEvent(), QMenu::changeEvent(), QMdiSubWindow::changeEvent(), QDockWidget::changeEvent(), QSplitter::childEvent(), QDialog::closeEvent(), QDockWidget::closeEvent(), QComboBoxPrivate::doHidePopup(), QSplitter::event(), QRhiWidget::event(), event(), QMenuBar::eventFilter(), QComboBoxPrivateContainer::eventFilter(), QSplitterPrivate::insertWidget(), isActiveWindow(), isVisibleTo(), QDialog::keyPressEvent(), QAbstractSpinBox::keyPressEvent(), QSvgWidget::load(), QSvgWidget::load(), QWidgetRepaintManager::markDirty(), QMdiSubWindow::maximizedButtonsWidget(), QMdiSubWindow::maximizedSystemMenuIconWidget(), QMenuBarPrivate::menuRect(), QStatusBarPrivate::messageRect(), QMdiSubWindow::minimumSizeHint(), QMenu::mouseMoveEvent(), QtAndroidMenu::onContextItemSelected(), operator<<(), QWidgetPrivate::overlappedRegion(), palette(), QGraphicsScenePrivate::removePopup(), QMdiSubWindow::resizeEvent(), QMdiSubWindowPrivate::restoreFocus(), scroll(), scroll(), QFileDialog::selectFile(), QFileDialogPrivate::selectionChanged(), QApplicationPrivate::sendSyntheticEnterLeave(), QGraphicsProxyWidgetPrivate::sendWidgetKeyEvent(), QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent(), QToolButton::setArrowType(), setAttribute(), QTabBar::setCurrentIndex(), QDockWidget::setFloating(), QAbstractButton::setIconSize(), QAbstractSpinBox::setLineEdit(), QComboBox::setLineEdit(), setMask(), QSplitter::setOrientation(), setParent(), QSplashScreen::setPixmap(), QtPrivate::QWellArray::setSelected(), QMenu::setSeparatorsCollapsible(), QStatusBar::setSizeGripEnabled(), QMenu::setTearOffEnabled(), QToolButton::setToolButtonStyle(), QProgressBar::setValue(), QWidgetWindowPrivate::setVisible(), setWindowState(), QErrorMessage::showMessage(), showMinimized(), QComboBox::showPopup(), QMdiSubWindow::showShaded(), QMacStyle::sizeFromContents(), snippet_ctor2(), QWidgetPrivate::subtractOpaqueSiblings(), QWidgetRepaintManager::sync(), QWidgetRepaintManager::sync(), QCalendarWidget::updateCell(), QCalendarWidget::updateCells(), QMenuBarPrivate::updateGeometries(), QComboBoxPrivateContainer::updateScrollers(), and QQuickControlsTestUtils::verifyButtonClickable().

◆ isVisibleTo()

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

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

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

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

isVisibleTo(0) is identical to isVisible().

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

Definition at line 8636 of file qwidget.cpp.

References isHidden(), isVisible(), and parentWidget().

Referenced by QGraphicsScene::focusNextPrevChild(), and QApplicationPrivate::focusNextPrevChild_helper().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isWindow()

bool QWidget::isWindow ( ) const
inline

Returns true if the widget is an independent window, otherwise returns false.

A window is a widget that isn't visually the child of any other widget and that usually has a frame and a \l{QWidget::setWindowTitle()}{window title}.

A window can have a \l{QWidget::parentWidget()}{parent widget}. It will then be grouped with its parent and deleted when the parent is deleted, minimized when the parent is minimized etc. If supported by the window manager, it will also have a common taskbar entry with its parent.

QDialog and QMainWindow widgets are by default windows, even if a parent widget is specified in the constructor. This behavior is specified by the Qt::Window flag.

See also
window(), isModal(), parentWidget()

Definition at line 811 of file qwidget.h.

References Qt::Window.

Referenced by ~QWidget(), QWidgetAnimator::animate(), QWidgetWindowPrivate::closestAcceptableGeometry(), correctWidgetContext(), create(), cursor(), destroy(), QWindowsVistaStyle::drawControl(), QMenu::event(), event(), QDockWidget::event(), focusInEvent(), focusNextPrevChild(), QApplicationPrivate::focusNextPrevChild_helper(), focusOutEvent(), frameGeometry(), frameSize(), QWidgetWindow::handleMoveEvent(), QApplicationPrivate::handlePaletteChanged(), QWidgetPrivate::hide_helper(), QWidgetPrivate::hideChildren(), QStyleOption::initFrom(), QWidgetItem::isEmpty(), QToolBar::isFloating(), QGraphicsSceneIndexPrivate::itemCollidesWithPath(), lower(), QWidgetRepaintManager::markNeedsFlush(), menuBarHeightForWidth(), QWidgetResizeHandler::mouseMoveEvent(), QSizeGrip::mousePressEvent(), move(), QDockWidgetLayout::nativeWindowDeco(), normalGeometry(), operator<<(), QWidgetPrivate::overlappedRegion(), QToolBar::paintEvent(), QCommonStyle::pixelMetric(), QMacStyle::pixelMetric(), pos(), QWidgetPrivate::prepareToRender(), q_createNativeChildrenAndSetParent(), raise(), QMdiAreaPrivate::resizeToMinimumTileSize(), QToolBarAreaLayout::saveState(), QApplicationPrivate::sendSyntheticEnterLeave(), QGraphicsScene::setActiveWindow(), setAttribute(), setBaseSize(), setFixedSize(), setGeometry(), setLayout(), setMask(), setMaximumSize(), setMinimumSize(), setParent(), setSizeIncrement(), setSizePolicy(), QDockWidget::setTitleBarWidget(), QFocusFrame::setWidget(), setWindowOpacity(), setWindowState(), show(), QWidgetPrivate::showChildren(), stackUnder(), QQC2::QWindowsXPStyle::standardIcon(), QWindowsVistaStyle::standardIcon(), QQC2::QWindowsXPStyle::standardPixmap(), QWindowsVistaStyle::standardPixmap(), QQC2::QWindowsStyle::styleHint(), QWidgetPrivate::subtractOpaqueSiblings(), unsetCursor(), QWidgetPrivate::updateFocusChild(), QToolBarLayout::updateMacBorderMetrics(), QGraphicsProxyWidgetPrivate::updateProxyGeometryFromWidget(), windowOpacity(), x(), and y().

◆ isWindowModified()

bool QWidget::isWindowModified ( ) const

Definition at line 11576 of file qwidget.cpp.

References testAttribute(), and Qt::WA_WindowModified.

Referenced by QMdiSubWindow::event(), qt_setWindowTitle_helperHelper(), and QMdiSubWindow::setWidget().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ keyboardGrabber()

QWidget * QWidget::keyboardGrabber ( )
static

Returns the widget that is currently grabbing the keyboard input.

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

See also
grabMouse(), mouseGrabber()

Definition at line 12844 of file qwidget.cpp.

References keyboardGrb.

Referenced by destroy(), QWidgetWindow::handleContextMenuEvent(), QWidgetWindow::handleKeyEvent(), and ungrabKeyboardForPopup().

+ Here is the caller graph for this function:

◆ keyPressEvent()

void QWidget::keyPressEvent ( QKeyEvent * event)
protectedvirtual

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

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

If you reimplement this handler, it is very important that you call the base class implementation if you do not act upon the key.

The default implementation closes popup widgets if the user presses the key sequence for QKeySequence::Cancel (typically the Escape key). Otherwise the event is ignored, so that the widget's parent can interpret it.

Note that QKeyEvent starts with isAccepted() == true, so you do not need to call QKeyEvent::accept() - just do not call the base class implementation if you act upon the key.

See also
keyReleaseEvent(), setFocusPolicy(), focusInEvent(), focusOutEvent(), event(), QKeyEvent

Reimplemented in QtPrivate::QWellArray, QDialog, QWhatsThat, QKeySequenceEdit, QLineEdit, QMenu, QMenuBar, QPushButton, QTabBar, QTabWidget, QQuickWidget, QFileDialogLineEdit, QAbstractButton, QComboBox, QAbstractSlider, QLabel, QInputDialogSpinBox, QInputDialogDoubleSpinBox, QMessageBox, QAbstractSpinBox, QCalendarWidget, QDateTimeEdit, and QMdiSubWindow.

Definition at line 9599 of file qwidget.cpp.

References QKeySequence::Cancel, close(), Qt::Popup, and windowType().

Referenced by event(), QInputDialogSpinBox::keyPressEvent(), QInputDialogDoubleSpinBox::keyPressEvent(), QCalendarWidget::keyPressEvent(), and QWidgetTextControl::processEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ keyReleaseEvent()

void QWidget::keyReleaseEvent ( QKeyEvent * event)
protectedvirtual

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

A widget must \l{setFocusPolicy()}{accept focus} initially and \l{hasFocus()}{have focus} in order to receive a key release event.

If you reimplement this handler, it is very important that you call the base class implementation if you do not act upon the key.

The default implementation ignores the event, so that the widget's parent can interpret it.

Note that QKeyEvent starts with isAccepted() == true, so you do not need to call QKeyEvent::accept() - just do not call the base class implementation if you act upon the key.

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

Reimplemented in QKeySequenceEdit, QLineEdit, QQuickWidget, QAbstractButton, QComboBox, and QAbstractSpinBox.

Definition at line 9634 of file qwidget.cpp.

Referenced by event(), QLineEdit::keyReleaseEvent(), QComboBox::keyReleaseEvent(), and QPlainTextEdit::keyReleaseEvent().

+ Here is the caller graph for this function:

◆ layout()

QLayout * QWidget::layout ( ) const

Returns the layout manager that is installed on this widget, or \nullptr if no layout manager is installed.

The layout manager sets the geometry of the widget's children that have been added to the layout.

See also
setLayout(), sizePolicy(), {Layout Management}

Definition at line 10202 of file qwidget.cpp.

References QLayout::layout().

Referenced by DragWidget::DragWidget(), FinalWidget::FinalWidget(), QComboBoxPrivateContainer::QComboBoxPrivateContainer(), Window::Window(), dropevents::Window::Window(), QGraphicsWidget::~QGraphicsWidget(), QLayout::~QLayout(), QMainWindow::centralWidget(), QDockWidget::changeEvent(), QStackedWidget::currentWidget(), dockedGeometry(), QDockWidget::event(), QMainWindow::event(), QWidgetItem::expandingDirections(), heightForWidth(), QWidgetItem::heightForWidth(), QDockWidget::initStyleOption(), QToolBar::initStyleOption(), QMainWindowPrivate::mainWindowLayout(), QWidgetItem::minimumHeightForWidth(), QMdiSubWindow::minimumSizeHint(), QApplicationPrivate::notify_helper(), QDockWidget::paintEvent(), QMainWindowLayout::plug(), QWidgetPrivate::prepareToRender(), QWidgetPrivate::safeAreaMargins(), QWizard::setButtonLayout(), QCalendarPopup::setCalendarWidget(), QMessageBox::setCheckBox(), QDockWidget::setFeatures(), QToolBar::setIconSize(), QComboBoxPrivateContainer::setItemView(), setLayout(), QPagePreview::setPageLayout(), QDockWidget::setTitleBarWidget(), QDockWidget::setWidget(), QMdiSubWindow::setWidget(), QComboBox::showPopup(), QMainWindow::takeCentralWidget(), QDockWidget::titleBarWidget(), QScrollAreaPrivate::updateScrollBars(), QComboBoxPrivateContainer::updateTopBottomMargin(), QDockWidget::widget(), and QStackedWidget::widget().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ layoutDirection()

Qt::LayoutDirection QWidget::layoutDirection ( ) const

Definition at line 4892 of file qwidget.cpp.

References Qt::LeftToRight, Qt::RightToLeft, testAttribute(), and Qt::WA_RightToLeft.

+ Here is the call graph for this function:

◆ leaveEvent()

void QWidget::leaveEvent ( QEvent * event)
protectedvirtual

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

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

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

Reimplemented in QComboBoxPrivateScroller, QMenu, QMenuBar, QToolButton, QDockWidgetTitleButton, QMdi::ControllerWidget, and QMdiSubWindow.

Definition at line 9724 of file qwidget.cpp.

Referenced by event(), QToolButton::leaveEvent(), and QDockWidgetTitleButton::leaveEvent().

+ Here is the caller graph for this function:

◆ locale()

QLocale QWidget::locale ( ) const

Definition at line 5918 of file qwidget.cpp.

References d.

◆ lower

void QWidget::lower ( )
slot

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

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

See also
raise(), stackUnder()

Definition at line 11948 of file qwidget.cpp.

References create(), d, isWindow(), QWindowContainer::parentWasLowered(), parentWidget(), Q_ASSERT, QCoreApplication::sendEvent(), testAttribute(), Qt::WA_WState_Created, and QEvent::ZOrderChange.

Referenced by QSplitterPrivate::insertWidget(), QAlphaWidget::render(), QSplitter::replaceWidget(), and QTabBar::setTabButton().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapFrom() [1/2]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 4248 of file qwidget.cpp.

References mapFrom(), QObject::parent(), pos, and QPointF::toPoint().

+ Here is the call graph for this function:

◆ mapFrom() [2/2]

QPointF QWidget::mapFrom ( const QWidget * parent,
const QPointF & pos ) const

Translates the widget coordinate pos from the coordinate system of parent to this widget's coordinate system.

The parent must not be \nullptr and must be a parent of the calling widget.

See also
mapTo(), mapFromParent(), mapFromGlobal(), underMouse()
Since
6.0

Definition at line 4229 of file qwidget.cpp.

References QObject::parent(), pos, and Q_ASSERT_X.

Referenced by QWidgetWindow::handleMoveEvent(), and mapFrom().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapFromGlobal() [1/2]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 12628 of file qwidget.cpp.

References mapFromGlobal(), pos, and QPointF::toPoint().

+ Here is the call graph for this function:

◆ mapFromGlobal() [2/2]

◆ mapFromParent() [1/2]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 4294 of file qwidget.cpp.

References pos.

◆ mapFromParent() [2/2]

QPointF QWidget::mapFromParent ( const QPointF & pos) const

Translates the parent widget coordinate pos to widget coordinates.

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

See also
mapToParent(), mapFrom(), mapFromGlobal(), underMouse()
Since
6.0

Definition at line 4286 of file qwidget.cpp.

References pos.

◆ mapTo() [1/2]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 4215 of file qwidget.cpp.

References mapTo(), QObject::parent(), pos, and QPointF::toPoint().

+ Here is the call graph for this function:

◆ mapTo() [2/2]

QPointF QWidget::mapTo ( const QWidget * parent,
const QPointF & pos ) const

Translates the widget coordinate pos to the coordinate system of parent.

The parent must not be \nullptr and must be a parent of the calling widget.

See also
mapFrom(), mapToParent(), mapToGlobal(), underMouse()
Since
6.0

Definition at line 4197 of file qwidget.cpp.

References QObject::parent(), pos, and Q_ASSERT_X.

Referenced by QWidgetRepaintManager::bltRect(), QScrollArea::ensureWidgetVisible(), QCalendarWidget::eventFilter(), findTextureWidgetsRecursively(), mapTo(), QWidgetRepaintManager::markDirty(), QWidgetRepaintManager::markNeedsFlush(), QWidgetPrivate::moveRect(), QGraphicsProxyWidget::subWidgetRect(), QWidgetRepaintManager::sync(), and QFocusFramePrivate::updateSize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapToGlobal() [1/2]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 12604 of file qwidget.cpp.

References mapToGlobal(), pos, and QPointF::toPoint().

+ Here is the call graph for this function:

◆ mapToGlobal() [2/2]

QPointF QWidget::mapToGlobal ( const QPointF & pos) const

Translates the widget coordinate pos to global screen coordinates.

For example, {mapToGlobal(QPointF(0,0))} would give the global coordinates of the top-left pixel of the widget.

See also
mapFromGlobal(), mapTo(), mapToParent()
Since
6.0

Definition at line 12594 of file qwidget.cpp.

References mapToGlobalTransform(), and pos.

Referenced by event(), QMainWindow::event(), QComboBoxPrivateContainer::eventFilter(), QPixmapStyle::eventFilter(), QSystemTrayIconSys::globalGeometry(), QWidgetWindow::handleContextMenuEvent(), QWidgetWindow::handleMouseEvent(), QtWaylandClient::QWaylandInputDevice::handleTouchPoint(), QLineEdit::inputMethodQuery(), QMdiSubWindow::keyPressEvent(), mapToGlobal(), QAbstractButtonPrivate::moveFocus(), QApplicationPrivate::pickMouseReceiver(), QMenuPrivate::popup(), QWhatsThisPrivate::say(), QDockWidget::setFloating(), QVideoWidget::setFullScreen(), QComboBox::showPopup(), and QCompleterPrivate::showPopup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapToParent() [1/2]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 4271 of file qwidget.cpp.

References pos.

◆ mapToParent() [2/2]

QPointF QWidget::mapToParent ( const QPointF & pos) const

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

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

See also
mapFromParent(), mapTo(), mapToGlobal(), underMouse()
Since
6.0

Definition at line 4263 of file qwidget.cpp.

References pos.

Referenced by QMdiSubWindow::mousePressEvent(), and QApplication::notify().

+ Here is the caller graph for this function:

◆ mask()

QRegion QWidget::mask ( ) const

Returns the mask currently set on a widget.

If no mask is set the return value will be an empty region.

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

Definition at line 10187 of file qwidget.cpp.

References d.

Referenced by ScreenWidget::ScreenWidget(), QWidgetPrivate::overlappedRegion(), QComboBoxPrivateContainer::resizeEvent(), and QWidgetPrivate::subtractOpaqueSiblings().

+ Here is the caller graph for this function:

◆ maximumHeight()

int QWidget::maximumHeight ( ) const
inline

Definition at line 829 of file qwidget.h.

◆ maximumSize()

QSize QWidget::maximumSize ( ) const

Definition at line 3774 of file qwidget.cpp.

References d, and QWIDGETSIZE_MAX.

◆ maximumWidth()

int QWidget::maximumWidth ( ) const
inline

Definition at line 826 of file qwidget.h.

◆ metric()

int QWidget::metric ( PaintDeviceMetric m) const
overrideprotectedvirtual

◆ minimumHeight()

int QWidget::minimumHeight ( ) const
inline

Definition at line 823 of file qwidget.h.

◆ minimumSize()

QSize QWidget::minimumSize ( ) const

Definition at line 3752 of file qwidget.cpp.

References d.

◆ minimumSizeHint()

◆ minimumWidth()

int QWidget::minimumWidth ( ) const
inline

Definition at line 820 of file qwidget.h.

◆ mouseDoubleClickEvent()

void QWidget::mouseDoubleClickEvent ( QMouseEvent * event)
protectedvirtual

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

The default implementation calls mousePressEvent().

Note
The widget will also receive mouse press and mouse release events in addition to the double click event. And if another widget that overlaps this widget disappears in response to press or release events, then this widget will only receive the double click event. It is up to the developer to ensure that the application interprets these events correctly.
See also
mousePressEvent(), mouseReleaseEvent(), mouseMoveEvent(), event(), QMouseEvent

Reimplemented in QLineEdit, QTabBar, QQuickWidget, QSystemTrayIconSys, QColumnViewGrip, QMdi::ControlLabel, and QMdiSubWindow.

Definition at line 9523 of file qwidget.cpp.

References mousePressEvent().

Referenced by event(), and QMdiSubWindow::mouseDoubleClickEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mouseGrabber()

QWidget * QWidget::mouseGrabber ( )
static

Returns the widget that is currently grabbing the mouse input.

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

See also
grabMouse(), keyboardGrabber()

Definition at line 12827 of file qwidget.cpp.

References qt_mouseGrb, and qt_pressGrab.

Referenced by destroy(), QWidgetWindow::handleEnterLeaveEvent(), QApplicationPrivate::pickMouseReceiver(), QApplicationPrivate::sendMouseEvent(), QApplicationPrivate::sendSyntheticEnterLeave(), and ungrabMouseForPopup().

+ Here is the caller graph for this function:

◆ mouseMoveEvent()

void QWidget::mouseMoveEvent ( QMouseEvent * event)
protectedvirtual

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

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

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

If you want to show a tooltip immediately, while the mouse is moving (e.g., to get the mouse coordinates with QMouseEvent::pos() and show them as a tooltip), you must first enable mouse tracking as described above. Then, to ensure that the tooltip is updated immediately, you must call QToolTip::showText() instead of setToolTip() in your implementation of mouseMoveEvent().

See also
setMouseTracking(), mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), event(), QMouseEvent, {Scribble Example}

Reimplemented in QtPrivate::QColorPicker, QtPrivate::QColorLuminancePicker, QWhatsThat, QCheckBox, QLineEdit, QMenu, QMenuBar, QPushButton, QRadioButton, QScrollBar, QSizeGrip, QSplitterHandle, QTabBar, QQuickWidget, QtPrivate::QColorWell, QtPrivate::QColorShowLabel, QTipLabel, QAbstractButton, QComboBoxPrivateScroller, QLabel, QSlider, DragWidget, FinalWidget, QColumnViewGrip, QAbstractSpinBox, QGroupBox, QMdi::ControllerWidget, QDial, and QMdiSubWindow.

Definition at line 9454 of file qwidget.cpp.

Referenced by event(), QSizeGrip::mouseMoveEvent(), QtPrivate::QColorWell::mouseMoveEvent(), and QMdiSubWindow::mouseMoveEvent().

+ Here is the caller graph for this function:

◆ mousePressEvent()

void QWidget::mousePressEvent ( QMouseEvent * event)
protectedvirtual

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

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

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

See also
mouseReleaseEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), event(), QMouseEvent, {Scribble Example}

Reimplemented in QtPrivate::QWellArray, QtPrivate::QColorPicker, QtPrivate::QColorLuminancePicker, QWhatsThat, QLineEdit, QMenu, QMenuBar, QScrollBar, QSizeGrip, QSplashScreen, QSplitterHandle, QTabBar, QToolButton, QQuickWidget, QtPrivate::QColorWell, QtPrivate::QColorShowLabel, QBalloonTip, QAbstractButton, QComboBox, QComboBoxPrivateContainer, QCalendarPopup, QSystemTrayIconSys, QLabel, QSlider, MyCheckBox, DragWidget, MainWindow, FinalWidget, QInputDialogSpinBox, QInputDialogDoubleSpinBox, QColumnViewGrip, QAbstractSpinBox, QCalendarWidget, QDateTimeEdit, QGroupBox, QMdi::ControllerWidget, QDial, QMdi::ControlLabel, and QMdiSubWindow.

Definition at line 9476 of file qwidget.cpp.

References QApplication::activePopupWidget(), close(), contains(), Qt::Popup, rect, and windowType().

Referenced by event(), mouseDoubleClickEvent(), QSizeGrip::mousePressEvent(), QCalendarPopup::mousePressEvent(), MyCheckBox::mousePressEvent(), QInputDialogSpinBox::mousePressEvent(), QInputDialogDoubleSpinBox::mousePressEvent(), QCalendarWidget::mousePressEvent(), and QMdiSubWindow::mousePressEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mouseReleaseEvent()

void QWidget::mouseReleaseEvent ( QMouseEvent * event)
protectedvirtual

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

See also
mousePressEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), event(), QMouseEvent, {Scribble Example}

Reimplemented in QtPrivate::QWellArray, QWhatsThat, QCalendarPopup, QLineEdit, QMenu, QMenuBar, QScrollBar, QSplitterHandle, QTabBar, QToolButton, QQuickWidget, QtPrivate::QColorWell, QtPrivate::QColorShowLabel, QAbstractButton, QComboBox, QComboBoxPrivateContainer, QLabel, QSlider, QColumnViewGrip, QAbstractSpinBox, QGroupBox, QMdi::ControllerWidget, QDial, QMdi::ControlLabel, QMdiSubWindow, and QSizeGrip.

Definition at line 9501 of file qwidget.cpp.

Referenced by event(), QMdiSubWindow::mouseReleaseEvent(), and QSizeGrip::mouseReleaseEvent().

+ Here is the caller graph for this function:

◆ move() [1/2]

void QWidget::move ( const QPoint & p)

Definition at line 7108 of file qwidget.cpp.

References d, geometry, height, isWindow(), QWindowContainer::parentWasMoved(), setAttribute(), testAttribute(), Qt::WA_Moved, Qt::WA_PendingMoveEvent, Qt::WA_WState_Created, width, x, QRect::y(), and y.

+ Here is the call graph for this function:

◆ move() [2/2]

void QWidget::move ( int x,
int y )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This corresponds to move(QPoint(x, y)).

Definition at line 880 of file qwidget.h.

Referenced by QDialog::adjustPosition(), QAlphaWidget::eventFilter(), QTabBarPrivate::layoutTab(), QTipLabel::placeTip(), QDateTimeEditPrivate::positionCalendarPopup(), MainWindow::readSettings(), restoreGeometry(), QAlphaWidget::run(), QRollEffect::run(), QDockWidget::setFloating(), QVideoWidget::setFullScreen(), QSplashScreen::setPixmap(), and QScrollAreaPrivate::updateWidgetPosition().

+ Here is the caller graph for this function:

◆ moveEvent()

void QWidget::moveEvent ( QMoveEvent * event)
protectedvirtual

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

When the widget receives this event, it is already at the new position.

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

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

Reimplemented in QSystemTrayIconSys, QRubberBand, QVideoWidget, QMdiSubWindow, and QSizeGrip.

Definition at line 9794 of file qwidget.cpp.

Referenced by event(), QSystemTrayIconSys::moveEvent(), and QMdiSubWindow::moveEvent().

+ Here is the caller graph for this function:

◆ nativeEvent()

bool QWidget::nativeEvent ( const QByteArray & eventType,
void * message,
qintptr * result )
protectedvirtual

This special event handler can be reimplemented in a subclass to receive native platform events identified by eventType which are passed in the message parameter.

In your reimplementation of this function, if you want to stop the event being handled by Qt, return true and set result. The result parameter has meaning only on Windows. If you return false, this native event is passed back to Qt, which translates the event into a Qt event and sends it to the widget.

Note
Events are only delivered to this event handler if the widget has a native window handle.
This function superseedes the event filter functions x11Event(), winEvent() and macEvent() of Qt 4.
See also
QAbstractNativeEventFilter

\table \header

  • Platform
  • Event Type Identifier
  • Message Type
  • Result Type \row
  • Windows
  • "windows_generic_MSG"
  • MSG *
  • LRESULT \row
  • macOS
  • "NSEvent"
  • NSEvent *
  • \row
  • XCB
  • "xcb_generic_event_t"
  • xcb_generic_event_t *
  • \endtable

Definition at line 10122 of file qwidget.cpp.

References Q_UNUSED.

Referenced by QWidgetWindow::nativeEvent().

+ Here is the caller graph for this function:

◆ nativeParentWidget()

QWidget * QWidget::nativeParentWidget ( ) const
Since
4.4

Returns the native parent for this widget, i.e. the next ancestor widget that has a system identifier, or \nullptr if it does not have any native parent.

See also
effectiveWinId()

Definition at line 4333 of file qwidget.cpp.

References QObject::parent(), and parentWidget().

Referenced by QWindowsVistaStylePrivate::backingStoreForWidget(), QWidgetPrivate::create(), effectiveWinId(), grabberWindow(), QWidgetWindow::handleMoveEvent(), QWidgetRepaintManager::markNeedsFlush(), q_createNativeChildrenAndSetParent(), and QApplicationPrivate::windowForWidget().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nextInFocusChain()

QWidget * QWidget::nextInFocusChain ( ) const

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

See also
previousInFocusChain()

Definition at line 6842 of file qwidget.cpp.

References d, and QWidgetPrivate::Next.

Referenced by QWidgetPrivate::determineLastFocusChild(), QApplicationPrivate::focusNextPrevChild_helper(), focusPath(), QLineEdit::inputMethodQuery(), iWantTheFocus(), QWidgetPrivate::reparentFocusChildren(), setFocusProxy(), QWidgetWindowPrivate::setFocusToTarget(), QMdiSubWindowPrivate::setFocusWidget(), and setTabOrder().

+ Here is the caller graph for this function:

◆ normalGeometry()

QRect QWidget::normalGeometry ( ) const

Definition at line 3668 of file qwidget.cpp.

References d, geometry, isFullScreen(), isMaximized(), and isWindow().

+ Here is the call graph for this function:

◆ overrideWindowFlags()

void QWidget::overrideWindowFlags ( Qt::WindowFlags flags)

Sets the window flags for the widget to flags, without telling the window system.

Warning
Do not call this function unless you really know what you're doing.
See also
setWindowFlags()

Definition at line 10557 of file qwidget.cpp.

◆ overrideWindowState()

void QWidget::overrideWindowState ( Qt::WindowStates newstate)

The function sets the window state on child widgets similar to setWindowState(). The difference is that the window state changed event has the isOverride() flag set. It exists mainly to keep QWorkspace working.

Definition at line 2900 of file qwidget.cpp.

References QCoreApplication::sendEvent().

Referenced by QMdiSubWindowPrivate::ensureWindowState(), and QMdiSubWindowPrivate::setActive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ paintEngine()

QPaintEngine * QWidget::paintEngine ( ) const
overridevirtual

Returns the widget's paint engine.

Note that this function should not be called explicitly by the user, since it's meant for reimplementation purposes only. The function is called by Qt internally, and the default implementation may not always return a valid pointer.

Implements QPaintDevice.

Definition at line 12506 of file qwidget.cpp.

References qWarning.

Referenced by QOpenGLWidget::paintEngine(), and setAttribute().

+ Here is the caller graph for this function:

◆ paintEvent()

void QWidget::paintEvent ( QPaintEvent * event)
protectedvirtual

This event handler can be reimplemented in a subclass to receive paint events passed in event.

A paint event is a request to repaint all or part of a widget. It can happen for one of the following reasons:

\list

  • repaint() or update() was invoked,
  • the widget was obscured and has now been uncovered, or
  • many other reasons. \endlist

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

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

When the paint event occurs, the update region has normally been erased, so you are painting on the widget's background.

The background can be set using setBackgroundRole() and setPalette().

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.

Note
Generally, you should refrain from calling update() or repaint() {inside} a paintEvent(). For example, calling update() or repaint() on children inside a paintEvent() results in undefined behavior; the child may or may not get a paint event.
Warning
If you are using a custom paint engine without Qt's backingstore, Qt::WA_PaintOnScreen must be set. Otherwise, QWidget::paintEngine() will never be called; the backingstore will be used instead.
See also
event(), repaint(), update(), QPainter, QPixmap, QPaintEvent, {Analog Clock}

Reimplemented in src_gui_painting_qpainter::MyWidget, src_gui_painting_qpainter2::MyWidget, SimpleTransformation, CombinedTransformation, BasicOperations, QPagePreview, QtPrivate::QWellArray, QtPrivate::QColorPicker, QtPrivate::QColorLuminancePicker, QtPrivate::QColorShowLabel, QFileDialogComboBox, MyPushButton, QWhatsThat, QBalloonTip, QSystemTrayIconSys, QtPrivate::QPrevNextCalButton, QCheckBox, QComboBoxPrivateScroller, QCommandLinkButton, QRollEffect, QFocusFrame, QFrame, QLabel, QLCDNumber, QLineEdit, QMenu, QMenuBarExtension, QMenuBar, QProgressBar, QPushButton, QRadioButton, QRubberBand, QScrollBar, QSizeGrip, QSplitterHandle, QStatusBar, QTabBar, QTabWidget, QToolBarExtension, QToolBarSeparator, QToolBoxButton, QToolButton, QOpenGLWidget, QRhiWidget, QTipLabel, QtPrivate::QCalToolButton, QComboBox, QComboBoxPrivateContainer, QAlphaWidget, QMenuPrivate::ScrollerTearOffItem, QMovableTabWidget, QAbstractButton, QSlider, plaintextlayout::Window, QWizardHeader, QWizard, SplitterHandle, MyWidget, QColumnViewGrip, QAbstractSpinBox, QDateTimeEdit, QDockWidgetTitleButton, QDockWidget, QGroupBox, QMdi::ControllerWidget, QToolBar, QQuickWidget, QSvgWidget, QMdi::ControlLabel, QMdiSubWindow, and QDial.

Definition at line 9776 of file qwidget.cpp.

Referenced by event(), plaintextlayout::Window::paintEvent(), and QMdiSubWindow::paintEvent().

+ Here is the caller graph for this function:

◆ palette()

const QPalette & QWidget::palette ( ) const

Definition at line 4514 of file qwidget.cpp.

References QPalette::Active, QPalette::Disabled, QPalette::Inactive, isActiveWindow, QApplicationPrivate::isBlockedByModal(), isEnabled(), isVisible(), and QPalette::setCurrentColorGroup().

+ Here is the call graph for this function:

◆ parentWidget()

QWidget * QWidget::parentWidget ( ) const
inline

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

Definition at line 904 of file qwidget.h.

References QObject::parent().

Referenced by QMenuBarExtension::QMenuBarExtension(), QTornOffMenu::QTornOffMenu(), QMenuPrivate::_q_actionTriggered(), QLayout::addChildWidget(), QGraphicsScene::addItem(), QFormLayoutPrivate::arrangeWidgets(), QStyleHelper::backgroundColor(), backgroundRole(), QMenuBar::changeEvent(), QToolButton::changeEvent(), QLayoutPrivate::checkWidget(), clearFocus(), QMdiSubWindow::closeEvent(), QDockWidget::closeEvent(), correctWidgetContext(), create(), cursor(), destroy(), QApplicationPrivate::dispatchEnterLeave(), QLayoutPrivate::doResize(), QQC2::QWindowsStyle::drawControl(), QCommonStyle::drawControl(), QGraphicsScene::drawItems(), QPixmapStyle::drawLineEdit(), QWindowsVistaStyle::drawPrimitive(), QQC2::QWindowsStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QBoxLayoutPrivate::effectiveMargins(), QDialogButtonBoxPrivate::ensureFirstAcceptIsDefault(), QDockWidget::event(), QMdiSubWindow::eventFilter(), QPixmapStyle::eventFilter(), focusNextPrevChild(), QLineEdit::focusOutEvent(), QLayoutPrivate::getMargin(), QFormLayoutPrivate::getStyle(), QWidgetWindow::handleExposeEvent(), QWidgetWindow::handleMoveEvent(), QMenuBarPrivate::handleReparent(), QWidgetPrivate::hide_helper(), QWidgetPrivate::hide_sys(), QTabBarPrivate::initStyleBaseOption(), QDockWidget::initStyleOption(), QToolBar::initStyleOption(), QToolBoxButton::initStyleOption(), QToolButton::initStyleOption(), QSplitterPrivate::insertWidget_helper(), isActiveWindow(), isChildOfQMdiSubWindow(), isEnabledTo(), QWindowsVistaStylePrivate::isItemViewDelegateLineEdit(), QWindowsVistaStylePrivate::isLineEditBaseColorSet(), isVisibleTo(), QGraphicsScenePrivate::itemsAtPosition(), QAbstractButton::keyPressEvent(), QMdiSubWindow::keyPressEvent(), lower(), QWidgetPrivate::lower_sys(), mainwindow_from_dock(), QGraphicsProxyWidgetPrivate::mapToReceiver(), QMdiSubWindow::mdiArea(), mdiAreaParent(), metric(), QMenuBar::minimumSizeHint(), QToolBoxButton::minimumSizeHint(), QColumnViewGrip::mouseDoubleClickEvent(), QSplitterHandle::mouseMoveEvent(), QWidgetResizeHandler::mouseMoveEvent(), QMdiSubWindow::mouseMoveEvent(), QSizeGrip::mousePressEvent(), QCalendarPopup::mousePressEvent(), QGraphicsScenePrivate::mousePressEventHandler(), QSplitterHandle::mouseReleaseEvent(), QColumnViewGrip::moveGrip(), QWidgetPrivate::moveRect(), nativeParentWidget(), QWidgetPrivate::naturalWidgetFont(), QWidgetPrivate::naturalWidgetPalette(), QDialog::open(), QSplitterHandle::paintEvent(), QToolBarSeparator::paintEvent(), QToolBoxButton::paintEvent(), QMacStyle::pixelMetric(), QWidgetPrivate::prepareToRender(), raise(), QWidgetPrivate::raise_sys(), QMdiSubWindowPrivate::removeBaseWidget(), QLayoutPrivate::reparentChildWidgets(), QSplitter::replaceWidget(), QMdiAreaPrivate::resizeToMinimumTileSize(), QWidgetPrivate::safeAreaMargins(), PressDelayHandler::sendMouseEvent(), QApplicationPrivate::sendSyntheticEnterLeave(), setAttribute(), QTabWidget::setCornerWidget(), setFocusProxy(), QToolBar::setIconSize(), QGraphicsWidgetPrivate::setLayoutDirection_helper(), setMask(), QMenuBar::setNativeMenuBar(), setParent(), setParent(), QtPrivate::QWellArray::setSelected(), QWidgetPrivate::setTextureChildSeen(), QBoxLayoutPrivate::setupGeom(), QFormLayoutPrivate::setupVerticalLayoutData(), QWidgetPrivate::setVisible(), QFocusFrame::setWidget(), QScrollArea::setWidget(), QMessageBox::setWindowModality(), QDialog::showEvent(), QMdiArea::sizeHint(), QMenuBarExtension::sizeHint(), QMenuBar::sizeHint(), QPushButton::sizeHint(), QSplitterHandle::sizeHint(), QToolBarSeparator::sizeHint(), QToolBoxButton::sizeHint(), stackUnder(), QWidgetPrivate::stackUnder_sys(), QWindows11Style::subElementRect(), QMacStyle::subElementRect(), QMenuPrivate::updateLayoutDirection(), QGraphicsProxyWidgetPrivate::updateProxyGeometryFromWidget(), QFocusFramePrivate::updateSize(), QWindowContainerPrivate::updateUsesNativeWidgets(), waitForPopup(), QStyleHelper::widgetSizePolicy(), and window().

+ Here is the call graph for this function:

◆ pos()

QPoint QWidget::pos ( ) const

Definition at line 3549 of file qwidget.cpp.

References d, isWindow(), Qt::Popup, and windowType().

+ Here is the call graph for this function:

◆ previousInFocusChain()

QWidget * QWidget::previousInFocusChain ( ) const

The previousInFocusChain function returns the previous widget in this widget's focus chain.

See also
nextInFocusChain()
Since
4.6

Definition at line 6856 of file qwidget.cpp.

References d, and QWidgetPrivate::Previous.

Referenced by QGraphicsProxyWidgetPrivate::findFocusChild(), focusPath(), QWidgetPrivate::reparentFocusChildren(), setFocusProxy(), QWidgetWindowPrivate::setFocusToTarget(), and setTabOrder().

+ Here is the caller graph for this function:

◆ raise

void QWidget::raise ( )
slot

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

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

Note
When using activateWindow(), you can call this function to ensure that the window is stacked on top.
See also
lower(), stackUnder()

Definition at line 11894 of file qwidget.cpp.

References create(), d, isWindow(), QWindowContainer::parentWasRaised(), parentWidget(), Q_ASSERT, rect, QCoreApplication::sendEvent(), testAttribute(), Qt::WA_WState_Created, and QEvent::ZOrderChange.

Referenced by QCalendarWidgetPrivate::_q_yearClicked(), QRubberBand::changeEvent(), QFocusFrame::eventFilter(), EditorWindow::find(), QMdiAreaPrivate::internalRaise(), qt_try_modal(), QTabBarPrivate::setupMovableTab(), QRubberBand::showEvent(), and QComboBox::showPopup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rect()

QRect QWidget::rect ( ) const
inline

Definition at line 889 of file qwidget.h.

◆ redirected()

QPaintDevice * QWidget::redirected ( QPoint * offset) const
overrideprotectedvirtual

Do PaintDevice rendering with the specified offset.

Reimplemented from QPaintDevice.

Definition at line 12965 of file qwidget.cpp.

References QPaintDevice::redirected().

Referenced by QOpenGLWidget::redirected(), and QWidgetPrivate::render().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ releaseKeyboard()

void QWidget::releaseKeyboard ( )

Releases the keyboard grab.

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

Definition at line 12808 of file qwidget.cpp.

References grabberWindow(), keyboardGrb, and window().

Referenced by destroy(), QWidgetResizeHandler::eventFilter(), and QWidgetResizeHandler::keyPressEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ releaseMouse()

void QWidget::releaseMouse ( )

Releases the mouse grab.

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

Definition at line 12759 of file qwidget.cpp.

References releaseMouseGrabOfWidget().

Referenced by destroy(), QWidgetResizeHandler::eventFilter(), grabMouseForWidget(), and QWidgetResizeHandler::keyPressEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ releaseShortcut()

void QWidget::releaseShortcut ( int id)

Removes the shortcut with the given id from Qt's shortcut system.

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

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

Definition at line 11830 of file qwidget.cpp.

References QGuiApplicationPrivate::instance(), Q_ASSERT, and qApp.

Referenced by QTabBar::removeTab(), QLabel::setBuddy(), QAbstractButton::setShortcut(), QTabBar::setTabText(), and QGroupBox::setTitle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeAction()

void QWidget::removeAction ( QAction * action)

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

See also
insertAction(), actions(), insertAction()

Definition at line 3186 of file qwidget.cpp.

References QEvent::ActionRemoved, QAction::associatedObjects(), d, QList< T >::removeAll(), and QCoreApplication::sendEvent().

Referenced by QMenu::clear(), QMenuBar::clear(), QToolBar::clear(), QtWidgetsActionPrivate::destroy(), insertAction(), QWidgetPlatformMenu::removeMenuItem(), QTornOffMenu::syncWithMenu(), and QToolBarLayout::takeAt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ render() [1/2]

void QWidget::render ( QPaintDevice * target,
const QPoint & targetOffset = QPoint(),
const QRegion & sourceRegion = QRegion(),
RenderFlags renderFlags = RenderFlags(DrawWindowBackground | DrawChildren) )
Since
4.3

Renders the sourceRegion of this widget into the target using renderFlags to determine how to render. Rendering starts at targetOffset in the target. For example:

If sourceRegion is a null region, this function will use QWidget::rect() as the region, i.e. the entire widget.

Ensure that you call QPainter::end() for the target device's active painter (if any) before rendering. For example:

...
painter.end();
myWidget->render(this);
Note
To obtain the contents of a QOpenGLWidget, use QOpenGLWidget::grabFramebuffer() instead.

Definition at line 5092 of file qwidget.cpp.

References render().

Referenced by render().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ render() [2/2]

void QWidget::render ( QPainter * painter,
const QPoint & targetOffset = QPoint(),
const QRegion & sourceRegion = QRegion(),
RenderFlags renderFlags = RenderFlags(DrawWindowBackground | DrawChildren) )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Renders the widget into the painter's QPainter::device().

Transformations and settings applied to the painter will be used when rendering.

Note
The painter must be active. On \macos the widget will be rendered into a QPixmap and then drawn by the painter.
See also
QPainter::device()

Definition at line 5112 of file qwidget.cpp.

References QPaintEnginePrivate::baseSystemClip, QPainter::clipRegion(), d, QPainter::deviceTransform(), engine, QPainter::hasClipping(), QPainter::isActive(), QTransform::map(), QPainter::opacity(), QPainter::paintEngine(), painter, QInternal::Printer, Q_ASSERT, Q_UNLIKELY, qFuzzyIsNull(), qWarning, QPaintEnginePrivate::setSystemTransformAndViewport(), QPaintEnginePrivate::setSystemViewport(), QPaintEnginePrivate::systemClip, QPaintEnginePrivate::systemStateChanged(), QPaintEnginePrivate::systemTransform, and QPaintEnginePrivate::systemViewport.

+ Here is the call graph for this function:

◆ repaint [1/4]

void QWidget::repaint ( )
slot

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

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

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

Definition at line 11089 of file qwidget.cpp.

References rect, and repaint().

Referenced by QAbstractButton::animateClick(), QWidgetWindow::event(), QAbstractButton::keyPressEvent(), QScrollBar::mouseMoveEvent(), QAbstractButton::mouseMoveEvent(), QScrollBar::mousePressEvent(), QTabBar::mousePressEvent(), QAbstractButton::mousePressEvent(), QAlphaWidget::render(), repaint(), QSplashScreen::repaint(), repaint(), QProgressBar::reset(), QProgressBar::setAlignment(), QtPrivate::QColorPicker::setCol(), QtPrivate::QColorLuminancePicker::setCol(), QProgressBar::setTextVisible(), and QProgressBar::setValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ repaint() [2/4]

void QWidget::repaint ( const QRect & rect)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version repaints a rectangle rect inside the widget.

Definition at line 11119 of file qwidget.cpp.

References d, and rect.

◆ repaint() [3/4]

void QWidget::repaint ( const QRegion & rgn)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version repaints a region rgn inside the widget.

Definition at line 11130 of file qwidget.cpp.

References d.

◆ repaint() [4/4]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version repaints a rectangle (x, y, w, h) inside the widget.

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

Definition at line 11102 of file qwidget.cpp.

References repaint(), x, and y.

+ Here is the call graph for this function:

◆ resize() [1/2]

void QWidget::resize ( const QSize & s)

Definition at line 7168 of file qwidget.cpp.

References d, geometry, maximumSize, minimumSize, setAttribute(), testAttribute(), Qt::WA_PendingResizeEvent, Qt::WA_Resized, Qt::WA_WState_Created, QRect::width(), x, and y.

+ Here is the call graph for this function:

◆ resize() [2/2]

void QWidget::resize ( int w,
int h )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This corresponds to resize(QSize(w, h)).

Definition at line 883 of file qwidget.h.

References resize().

Referenced by QWhatsThat::QWhatsThat(), QMenu::actionEvent(), adjustSize(), QMenu::changeEvent(), QMenuBar::changeEvent(), QWidgetPrivate::create(), QMdiSubWindow::event(), QPrintPreviewDialogPrivate::init(), main(), main(), QColumnViewGrip::moveGrip(), MainWindow::readSettings(), QColumnViewPreviewColumn::resizeEvent(), QVideoWidget::resizeEvent(), QMdiAreaPrivate::resizeToMinimumTileSize(), QAlphaWidget::run(), QRollEffect::run(), setFixedSize(), QWidgetPrivate::setGeometry_sys(), setMaximumSize(), setMinimumSize(), QSplashScreen::setPixmap(), QMenu::setTearOffEnabled(), MyScrollArea::setWidget(), QScrollArea::setWidget(), QMdiSubWindow::showEvent(), QMdiSubWindow::showShaded(), QScrollAreaPrivate::updateScrollBars(), and QTipLabel::updateSize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resizeEvent()

void QWidget::resizeEvent ( QResizeEvent * event)
protectedvirtual

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

When resizeEvent() is called, the widget already has its new geometry. The old size is accessible through QResizeEvent::oldSize().

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

See also
moveEvent(), event(), resize(), QResizeEvent, paintEvent(), {Scribble Example}

Reimplemented in QtPrivate::QColorPicker, QDialog, QBalloonTip, QSystemTrayIconSys, QMenuBar, QRubberBand, QSplitter, QSplitterHandle, QStatusBar, QTabBar, QTabWidget, QQuickWidget, QOpenGLWidget, QRhiWidget, QTipLabel, QComboBox, QComboBoxPrivateContainer, QMessageBox, QProgressDialog, QWizard, QAbstractSpinBox, QCalendarWidget, QGroupBox, QVideoWidget, QDial, and QMdiSubWindow.

Definition at line 9815 of file qwidget.cpp.

Referenced by event(), QtPrivate::QColorPicker::resizeEvent(), QBalloonTip::resizeEvent(), QSystemTrayIconSys::resizeEvent(), QSplitterHandle::resizeEvent(), QStatusBar::resizeEvent(), QTabWidget::resizeEvent(), QTipLabel::resizeEvent(), QComboBoxPrivateContainer::resizeEvent(), QAbstractSpinBox::resizeEvent(), QCalendarWidget::resizeEvent(), QGroupBox::resizeEvent(), QVideoWidget::resizeEvent(), QDial::resizeEvent(), and QMdiSubWindow::resizeEvent().

+ Here is the caller graph for this function:

◆ restoreGeometry()

bool QWidget::restoreGeometry ( const QByteArray & geometry)
Since
4.2

Restores the geometry and state of top-level widgets stored in the byte array geometry. Returns true on success; otherwise returns false.

If the restored geometry is off-screen, it will be modified to be inside the available screen geometry.

To restore geometry saved using QSettings, you can use code like this:

QSettings settings("MyCompany", "MyApp");
myWidget->restoreGeometry(settings.value("myWidget/geometry").toByteArray());

See the \l{Window Geometry} documentation for an overview of geometry issues with windows.

Use QMainWindow::restoreState() to restore the geometry and the state of toolbars and dock widgets.

See also
saveGeometry(), QSettings, QMainWindow::saveState(), QMainWindow::restoreState()

Definition at line 7446 of file qwidget.cpp.

References QWidgetPrivate::checkRestoredGeometry(), currentMajorVersion, fullScreen, geometry, maximized, move(), QStyle::PM_TitleBarHeight, qMax(), screen(), QGuiApplication::screens(), setGeometry(), setWindowState(), QRect::size(), size, sizeHint, QApplication::style(), QRect::topLeft(), Qt::WindowFullScreen, Qt::WindowMaximized, Qt::WindowNoState, and windowState().

+ Here is the call graph for this function:

◆ saveGeometry()

QByteArray QWidget::saveGeometry ( ) const
Since
4.2 Saves the current geometry and state for top-level widgets.

To save the geometry when the window closes, you can implement a close event like this:

See the \l{Window Geometry} documentation for an overview of geometry issues with windows.

Use QMainWindow::saveState() to save the geometry and the state of toolbars and dock widgets.

See also
restoreGeometry(), QMainWindow::saveState(), QMainWindow::restoreState()

Definition at line 7334 of file qwidget.cpp.

References frameGeometry, geometry, normalGeometry, screen(), QGuiApplication::screens(), width, Qt::WindowFullScreen, Qt::WindowMaximized, windowState(), and QIODeviceBase::WriteOnly.

+ Here is the call graph for this function:

◆ screen()

◆ scroll() [1/2]

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

Scrolls the widget including its children dx pixels to the right and dy downward.

Both dx and dy may be negative.

After scrolling, the widgets will receive paint events for the areas that need to be repainted. For widgets that Qt knows to be opaque, this is only the newly exposed parts. For example, if an opaque widget is scrolled 8 pixels to the left, only an 8-pixel wide stripe at the right edge needs updating.

Since widgets propagate the contents of their parents by default, you need to set the \l autoFillBackground property, or use setAttribute() to set the Qt::WA_OpaquePaintEvent attribute, to make a widget opaque.

For widgets that use contents propagation, a scroll will cause an update of the entire scroll area.

See also
{Transparency and Double Buffering}

Definition at line 11005 of file qwidget.cpp.

References QObject::children(), d, isVisible(), proxy, rect, size, QRect::translated(), and updatesEnabled.

Referenced by QMenuPrivate::drawScroller(), QMenuPrivate::init(), QMenuPrivate::setFirstActionActive(), and QMenuPrivate::updateActionRects().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ scroll() [2/2]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version only scrolls r and does not move the children of the widget.

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

See also
QScrollArea

Definition at line 11044 of file qwidget.cpp.

References QObject::children(), d, isVisible(), proxy, rect, size, and updatesEnabled.

+ Here is the call graph for this function:

◆ setAcceptDrops()

void QWidget::setAcceptDrops ( bool on)

Definition at line 3436 of file qwidget.cpp.

References setAttribute(), and Qt::WA_AcceptDrops.

Referenced by DragWidget::DragWidget(), QWindowContainer::QWindowContainer(), dropevents::Window::Window(), and QGraphicsView::setupViewport().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setAttribute()

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

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

See also
testAttribute()

Definition at line 11276 of file qwidget.cpp.

References Qt::AA_DontCreateNativeWidgetSiblings, QEvent::AcceptDropsChange, Qt::ApplicationModal, createWinId(), d, Qt::Desktop, QGuiApplication::focusObject(), focusWidget(), QPlatformIntegration::hasCapability(), i, Qt::ImEnabled, QObject::inherits(), QGuiApplication::inputMethod(), internalWinId(), isEnabled(), isVisible(), isWindow(), QEvent::MouseTrackingChange, QPlatformIntegration::NativeWidgets, Qt::NonModal, paintEngine(), parentWidget(), QGuiApplicationPrivate::platformIntegration(), Q_FALLTHROUGH, qobject_cast< QWidget * >(), QCoreApplication::sendEvent(), setAttribute(), setAttribute_internal(), QEvent::TabletTrackingChange, QCoreApplication::testAttribute(), testAttribute(), Qt::WA_AcceptDrops, Qt::WA_AcceptTouchEvents, Qt::WA_AttributeCount, Qt::WA_DontShowOnScreen, Qt::WA_DropSiteRegistered, Qt::WA_InputMethodEnabled, Qt::WA_MacMiniSize, Qt::WA_MacNormalSize, Qt::WA_MacSmallSize, Qt::WA_MouseTracking, Qt::WA_NativeWindow, Qt::WA_NoChildEventsForParent, Qt::WA_NoChildEventsFromChildren, Qt::WA_NoSystemBackground, Qt::WA_OpaquePaintEvent, Qt::WA_PaintOnScreen, Qt::WA_ShowModal, Qt::WA_StaticContents, Qt::WA_TabletTracking, Qt::WA_TranslucentBackground, Qt::WA_TransparentForMouseEvents, Qt::WA_UpdatesDisabled, Qt::WA_WindowPropagation, Qt::WA_WState_Created, Qt::WA_X11NetWmWindowTypeCombo, Qt::WA_X11NetWmWindowTypeDesktop, Qt::WA_X11NetWmWindowTypeDialog, Qt::WA_X11NetWmWindowTypeDND, Qt::WA_X11NetWmWindowTypeDock, Qt::WA_X11NetWmWindowTypeDropDownMenu, Qt::WA_X11NetWmWindowTypeMenu, Qt::WA_X11NetWmWindowTypeNotification, Qt::WA_X11NetWmWindowTypePopupMenu, Qt::WA_X11NetWmWindowTypeSplash, Qt::WA_X11NetWmWindowTypeToolBar, Qt::WA_X11NetWmWindowTypeToolTip, Qt::WA_X11NetWmWindowTypeUtility, and windowType().

Referenced by QAlphaWidget::QAlphaWidget(), QCalendarPopup::QCalendarPopup(), QtPrivate::QColorPicker::QColorPicker(), QComboBoxPrivateContainer::QComboBoxPrivateContainer(), QComboBoxPrivateScroller::QComboBoxPrivateScroller(), QPageSetupDialog::QPageSetupDialog(), QPageSetupDialog::QPageSetupDialog(), QPageSetupWidget::QPageSetupWidget(), QPrintDialog::QPrintDialog(), QPrintDialog::QPrintDialog(), QRollEffect::QRollEffect(), QRubberBand::QRubberBand(), QSystemTrayIconSys::QSystemTrayIconSys(), QTornOffMenu::QTornOffMenu(), QWhatsThat::QWhatsThat(), QMessageBox::about(), QMessageBox::aboutQt(), QMenu::actionEvent(), QWidgetTextControlPrivate::contextMenuEvent(), QLineEdit::contextMenuEvent(), QLabel::contextMenuEvent(), QMainWindow::contextMenuEvent(), create(), destroy(), QAbstractButton::event(), QLabel::event(), event(), QMdiSubWindow::event(), QSizeGrip::eventFilter(), QDialog::exec(), QFileDialog::getOpenFileContent(), QScroller::grabGesture(), grabShortcut(), QWidgetWindow::handleExposeEvent(), QWidgetPrivate::hideChildren(), QMenu::mousePressEvent(), QMenuBar::mousePressEvent(), QComboBoxPrivateContainer::mousePressEvent(), QCalendarPopup::mousePressEvent(), QCalendarWidget::mousePressEvent(), move(), QApplicationPrivate::notify_helper(), QDialog::open(), QAndroidStyle::polish(), QWindows11Style::polish(), QWindowsVistaStyle::polish(), QPixmapStyle::polish(), QWidgetPrivate::prepareToRender(), QAlphaWidget::render(), resize(), QSplitterHandle::resizeEvent(), QAlphaWidget::run(), QRollEffect::run(), QFileDialog::saveFileContent(), setAcceptDrops(), QFileDialog::setAcceptMode(), setAttribute(), QDateTimeEdit::setCalendarPopup(), setCursor(), QComboBox::setEditable(), setEnabled(), QDockWidget::setFloating(), setFont(), QFrame::setFrameStyle(), setGeometry(), setLayoutDirection(), QComboBox::setLineEdit(), setLocale(), setMaximumSize(), setMinimumSize(), QDialog::setModal(), QAbstractSlider::setOrientation(), QProgressBar::setOrientation(), QSplitter::setOrientation(), setPalette(), setParent(), QSplashScreen::setPixmap(), QLineEdit::setReadOnly(), setSizePolicy(), setStyle(), setUpdatesEnabled(), QGraphicsView::setupViewport(), setVisible(), QMdiSubWindow::setWidget(), QGraphicsProxyWidgetPrivate::setWidget_helper(), setWindowIcon(), setWindowModality(), setWindowModified(), setWindowOpacity(), QWidgetPrivate::showChildren(), QFileDialogPrivate::showContextMenu(), QDialog::showEvent(), QApplicationPrivate::translateRawTouchEvent(), QMacStyle::unpolish(), QAndroidStyle::unpolish(), QWindowsVistaStyle::unpolish(), unsetCursor(), unsetLayoutDirection(), unsetLocale(), and winId().

+ Here is the call graph for this function:

◆ setAutoFillBackground()

void QWidget::setAutoFillBackground ( bool enabled)

Definition at line 330 of file qwidget.cpp.

References d, enabled, and update().

Referenced by QCalendarWidgetPrivate::createNavigationBar(), QWindows11Style::polish(), QWizardPrivate::recreateLayout(), QGraphicsView::setupViewport(), and QScrollArea::setWidget().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setBackgroundRole()

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

Sets the background role of the widget to role.

The background role defines the brush from the widget's \l palette that is used to render the background.

If role is QPalette::NoRole, then the widget inherits its parent's background role.

Note that styles are free to choose any color from the palette. You can modify the palette or set a style sheet if you don't achieve the result you want with setBackgroundRole().

See also
backgroundRole(), foregroundRole()

Definition at line 4391 of file qwidget.cpp.

References d.

Referenced by QTipLabel::QTipLabel(), QToolBox::QToolBox(), QToolBoxButton::QToolBoxButton(), QWizardHeader::QWizardHeader(), ScreenWidget::ScreenWidget(), QCalendarWidgetPrivate::createNavigationBar(), and QWizardPrivate::recreateLayout().

+ Here is the caller graph for this function:

◆ setBaseSize() [1/2]

void QWidget::setBaseSize ( const QSize & s)
inline

Definition at line 841 of file qwidget.h.

◆ setBaseSize() [2/2]

void QWidget::setBaseSize ( int basew,
int baseh )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This corresponds to setBaseSize(QSize(basew, baseh)).

Sets the widgets base size to width basew and height baseh.

Definition at line 4054 of file qwidget.cpp.

References QTLWExtra::basew, d, and isWindow().

+ Here is the call graph for this function:

◆ setContentsMargins() [1/2]

void QWidget::setContentsMargins ( const QMargins & margins)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.6

The setContentsMargins function sets the margins around the widget's contents.

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

Changing the margins will trigger a resizeEvent().

See also
contentsRect(), contentsMargins()

Definition at line 7617 of file qwidget.cpp.

References QMargins::bottom(), QMargins::left(), QMargins::right(), setContentsMargins(), and QMargins::top().

+ Here is the call graph for this function:

◆ setContentsMargins() [2/2]

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

Sets the margins around the contents of the widget to have the sizes left, top, right, and bottom.

The margins are used by the layout system, and may be used by subclasses to specify the area to draw in (e.g. excluding the frame).

Changing the margins will trigger a resizeEvent().

See also
contentsRect(), contentsMargins()

Definition at line 7587 of file qwidget.cpp.

References d.

Referenced by QTornOffMenu::QTornOffMenu(), QMdiSubWindow::event(), QWindowsVistaStyle::polish(), QPixmapStyle::polish(), QWizardPrivate::recreateLayout(), QSplitterHandle::resizeEvent(), setContentsMargins(), QFrame::setFrameRect(), QMessageBoxPrivate::setupLayout(), and QWindowsVistaStyle::unpolish().

+ Here is the caller graph for this function:

◆ setContextMenuPolicy()

void QWidget::setContextMenuPolicy ( Qt::ContextMenuPolicy policy)

Definition at line 7783 of file qwidget.cpp.

References policy.

◆ setCursor()

void QWidget::setCursor ( const QCursor & cursor)

Definition at line 4960 of file qwidget.cpp.

References Qt::ArrowCursor, cursor, QEvent::CursorChange, d, QCoreApplication::sendEvent(), setAttribute(), QCursor::shape(), and Qt::WA_SetCursor.

Referenced by QWhatsThat::QWhatsThat(), QApplicationPrivate::dispatchEnterLeave(), QToolBar::event(), QWhatsThat::mouseMoveEvent(), QSizeGrip::moveEvent(), QSplitterHandle::setOrientation(), and QLineEdit::setReadOnly().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDisabled

void QWidget::setDisabled ( bool disable)
slot

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

See the \l enabled documentation for more information.

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

Definition at line 3450 of file qwidget.cpp.

References setEnabled().

+ Here is the call graph for this function:

◆ setEnabled

◆ setFixedHeight()

void QWidget::setFixedHeight ( int h)

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

Provided for convenience.

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

Definition at line 4175 of file qwidget.cpp.

References d, maximumSize, minimumSize, setMaximumSize(), setMinimumSize(), Qt::Vertical, and width.

Referenced by QWizardHeader::QWizardHeader(), and QWizardPrivate::recreateLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFixedSize() [1/2]

void QWidget::setFixedSize ( const QSize & s)

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

This will override the default size constraints set by QLayout.

To remove constraints, set the size to QWIDGETSIZE_MAX.

Alternatively, if you want the widget to have a fixed size based on its contents, you can call QLayout::setSizeConstraint(QLayout::SetFixedSize);

See also
maximumSize, minimumSize

Definition at line 4082 of file qwidget.cpp.

References setFixedSize().

Referenced by QMdi::ControlLabel::ControlLabel(), QMdi::ControlLabel::event(), setFixedSize(), and QWizardHeader::setup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFixedSize() [2/2]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the width of the widget to w and the height to h.

Definition at line 4095 of file qwidget.cpp.

References d, isWindow(), QWIDGETSIZE_MAX, and resize().

+ Here is the call graph for this function:

◆ setFixedWidth()

void QWidget::setFixedWidth ( int w)

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

Provided for convenience.

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

Definition at line 4155 of file qwidget.cpp.

References d, height, Qt::Horizontal, maximumSize, minimumSize, setMaximumSize(), and setMinimumSize().

+ Here is the call graph for this function:

◆ setFocus [1/2]

void QWidget::setFocus ( )
inlineslot

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the \l{isActiveWindow()}{active window}.

Definition at line 423 of file qwidget.h.

References Qt::OtherFocusReason, and setFocus().

Referenced by QGroupBoxPrivate::_q_fixFocus(), QCalendarWidgetPrivate::_q_yearClicked(), QGraphicsScenePrivate::addPopup(), QAbstractButton::animateClick(), QAbstractButton::event(), QGroupBox::event(), QWindowContainer::eventFilter(), QCalendarWidget::eventFilter(), QGraphicsProxyWidget::focusNextPrevChild(), QMenu::focusNextPrevChild(), QWidgetWindow::handleFocusInEvent(), QPrintPreviewDialogPrivate::init(), QMdiSubWindowPrivate::leaveInteractiveMode(), QCalendarWidget::mousePressEvent(), QAbstractButtonPrivate::moveFocus(), QApplicationPrivate::notifyActiveWindowChange(), QApplicationPrivate::openPopup(), QMdiSubWindowPrivate::restoreFocus(), QMenuBarPrivate::setCurrentAction(), QMenuPrivate::setCurrentAction(), QMessageBox::setDefaultButton(), setFocus(), setFocus(), setFocusProxy(), QWidgetWindowPrivate::setFocusToTarget(), QMdiSubWindowPrivate::setFocusWidget(), QMenuBarPrivate::setKeyboardMode(), QDialogPrivate::setVisible(), and QWizardPrivate::switchToPage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFocus() [2/2]

void QWidget::setFocus ( Qt::FocusReason reason)

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

The reason argument will be passed into any focus event sent from this function, it is used to give an explanation of what caused the widget to get focus. If the window is not active, the widget will be given the focus when the window becomes active.

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

Note
On embedded platforms, setFocus() will not cause an input panel to be opened by the input method. If you want this to happen, you have to send a QEvent::RequestSoftwareInputPanel event to the widget yourself.

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

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

Warning
If you call setFocus() in a function which may itself be called from focusOutEvent() or focusInEvent(), you may get an infinite recursion.
See also
hasFocus(), clearFocus(), focusInEvent(), focusOutEvent(), setFocusPolicy(), focusWidget(), QApplication::focusWidget(), grabKeyboard(), grabMouse(), {Keyboard Focus in Widgets}, QEvent::RequestSoftwareInputPanel

Definition at line 6493 of file qwidget.cpp.

References QApplicationPrivate::focus_widget, QEvent::FocusAboutToChange, QEvent::FocusIn, QEvent::FocusOut, focusProxy(), QApplication::focusWidget(), focusWidget(), QGuiApplication::inputMethod(), isEnabled(), isHidden(), Qt::MenuBarFocusReason, Qt::NoFocusReason, Qt::PopupFocusReason, QCoreApplication::sendEvent(), setFocus(), QApplicationPrivate::setFocusWidget(), testAttribute(), Qt::WA_InputMethodEnabled, and window().

+ Here is the call graph for this function:

◆ setFocusPolicy()

◆ setFocusProxy()

void QWidget::setFocusProxy ( QWidget * w)

Sets the widget's focus proxy to widget w.

If w is \nullptr, the function resets this widget to have no focus proxy.

Some widgets can "have focus", but create a child widget, such as QLineEdit, to actually handle the focus. In this case, the widget can set the line edit to be its focus proxy.

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

See also
focusProxy()

Definition at line 6365 of file qwidget.cpp.

References child, QObject::children(), className, d, QApplicationPrivate::focus_widget, fp, isAncestorOf(), metaObject(), nextInFocusChain(), QObject::objectName, Qt::OtherFocusReason, parentWidget(), previousInFocusChain(), Q_ASSERT, Q_UNLIKELY, qWarning, setFocus(), and toLocal8Bit().

Referenced by QFontDialogPrivate::init(), QKeySequenceEditPrivate::init(), QDialogButtonBoxPrivate::layoutButtons(), and QTabWidget::setTabBar().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFont()

void QWidget::setFont ( const QFont & font)

Definition at line 4667 of file qwidget.cpp.

References d, font, qt_styleSheet(), QFont::resolve(), QFont::resolveMask(), setAttribute(), style(), and Qt::WA_SetFont.

Referenced by QWizardHeader::QWizardHeader(), QComboBox::changeEvent(), QCalendarWidgetPrivate::createNavigationBar(), QWindowsVistaStyle::polish(), QWizardPrivate::recreateLayout(), QToolButton::setDefaultAction(), QWidgetPlatformMenu::setFont(), QWindowsVistaStyle::unpolish(), and QFontDialogPrivate::updateSampleFont().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setForegroundRole()

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

Sets the foreground role of the widget to role.

The foreground role defines the color from the widget's \l palette that is used to draw the foreground.

If role is QPalette::NoRole, the widget uses a foreground role that contrasts with the background role.

Note that styles are free to choose any color from the palette. You can modify the palette or set a style sheet if you don't achieve the result you want with setForegroundRole().

See also
foregroundRole(), backgroundRole()

Definition at line 4456 of file qwidget.cpp.

References d.

Referenced by QTipLabel::QTipLabel().

+ Here is the caller graph for this function:

◆ setGeometry() [1/2]

void QWidget::setGeometry ( const QRect & r)

Definition at line 7184 of file qwidget.cpp.

References d, isWindow(), maximumSize, minimumSize, QWindowContainer::parentWasMoved(), setAttribute(), testAttribute(), Qt::WA_Moved, Qt::WA_PendingMoveEvent, Qt::WA_PendingResizeEvent, Qt::WA_Resized, and Qt::WA_WState_Created.

+ Here is the call graph for this function:

◆ setGeometry() [2/2]

◆ setHidden

void QWidget::setHidden ( bool hidden)
slot

Convenience function, equivalent to setVisible(!hidden).

Definition at line 8372 of file qwidget.cpp.

References setVisible().

+ Here is the call graph for this function:

◆ setInputMethodHints()

void QWidget::setInputMethodHints ( Qt::InputMethodHints hints)

Definition at line 9964 of file qwidget.cpp.

References d, QGuiApplication::focusObject(), Qt::ImHints, QGuiApplication::inputMethod(), and Q_UNUSED.

Referenced by QInputDialog::getItem(), QInputDialog::getMultiLineText(), QInputDialog::getText(), QLineEdit::setEchoMode(), and QGraphicsViewPrivate::updateInputMethodSensitivity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setLayout()

void QWidget::setLayout ( QLayout * layout)

Sets the layout manager for this widget to layout.

If there already is a layout manager installed on this widget, QWidget won't let you install another. You must first delete the existing layout manager (returned by layout()) before you can call setLayout() with the new layout.

If layout is the layout manager on a different widget, setLayout() will reparent the layout and make it the layout manager for this widget.

Example:

An alternative to calling this function is to pass this widget to the layout's constructor.

The QWidget will take ownership of layout.

See also
layout(), {Layout Management}

Definition at line 10233 of file qwidget.cpp.

References className, d, QByteArray::data(), QLayout::invalidate(), isWindow(), layout(), QLayout::layout(), metaObject(), QObject::objectName, QObject::parent(), Q_UNLIKELY, qWarning, QObject::setParent(), QString::toLocal8Bit(), and toLocal8Bit().

Referenced by Window::Window(), and QCalendarWidgetPrivate::createNavigationBar().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setLayoutDirection()

void QWidget::setLayoutDirection ( Qt::LayoutDirection direction)

Definition at line 4879 of file qwidget.cpp.

References d, direction, Qt::LayoutDirectionAuto, setAttribute(), unsetLayoutDirection(), and Qt::WA_SetLayoutDirection.

Referenced by QTornOffMenu::QTornOffMenu(), and QComboBoxPrivate::updateLayoutDirection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setLocale()

void QWidget::setLocale ( const QLocale & locale)

Definition at line 5910 of file qwidget.cpp.

References d, locale, setAttribute(), and Qt::WA_SetLocale.

+ Here is the call graph for this function:

◆ setMask() [1/2]

void QWidget::setMask ( const QBitmap & bitmap)

Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible.

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

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

The following code shows how an image with an alpha channel can be used to generate a mask for a widget:

QLabel topLevelLabel;
QPixmap pixmap(":/images/tux.png");
topLevelLabel.setPixmap(pixmap);
topLevelLabel.setMask(pixmap.mask());

The label shown by this code is masked using the image it contains, giving the appearance that an irregularly-shaped image is being drawn directly onto the screen.

Masked widgets receive mouse events only on their visible portions.

See also
clearMask(), windowOpacity()

Definition at line 13097 of file qwidget.cpp.

References setMask().

Referenced by clearMask(), QMenu::event(), QSplitterHandle::resizeEvent(), QTipLabel::resizeEvent(), QComboBoxPrivateContainer::resizeEvent(), and setMask().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setMask() [2/2]

void QWidget::setMask ( const QRegion & region)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Causes only the parts of the widget which overlap region to be visible.

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

Since QRegion allows arbitrarily complex regions to be created, widget masks can be made to suit the most unconventionally-shaped windows, and even allow widgets to be displayed with holes in them. Note that this effect can be slow if the region is particularly complex.

Widget masks are used to hint to the window system that the application does not want mouse events for areas outside the mask. On most systems, they also result in coarse visual clipping. To get smooth window edges, use translucent background and anti-aliased painting instead, as shown in the \l{Translucent Background} example.

See also
windowOpacity

Definition at line 13013 of file qwidget.cpp.

References d, isVisible(), isWindow(), parentWidget(), rect, testAttribute(), update(), and Qt::WA_WState_Created.

+ Here is the call graph for this function:

◆ setMaximumHeight()

void QWidget::setMaximumHeight ( int maxh)

Definition at line 4139 of file qwidget.cpp.

References d, maximumSize, QWIDGETSIZE_MAX, setMaximumSize(), Qt::Vertical, and width.

+ Here is the call graph for this function:

◆ setMaximumSize() [1/2]

void QWidget::setMaximumSize ( const QSize & s)
inline

Definition at line 835 of file qwidget.h.

Referenced by setFixedHeight(), setFixedWidth(), setMaximumHeight(), setMaximumWidth(), and QWizardHeader::setup().

+ Here is the caller graph for this function:

◆ setMaximumSize() [2/2]

void QWidget::setMaximumSize ( int maxw,
int maxh )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This function corresponds to setMaximumSize(QSize(maxw, maxh)).

Sets the maximum width to maxw and the maximum height to maxh.

Definition at line 4005 of file qwidget.cpp.

References d, height, isWindow(), qMin(), resize(), setAttribute(), testAttribute(), Qt::WA_Resized, and width.

+ Here is the call graph for this function:

◆ setMaximumWidth()

void QWidget::setMaximumWidth ( int maxw)

Definition at line 4130 of file qwidget.cpp.

References d, height, Qt::Horizontal, maximumSize, QWIDGETSIZE_MAX, and setMaximumSize().

Referenced by QPrintPreviewDialogPrivate::updatePageNumLabel().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setMinimumHeight()

void QWidget::setMinimumHeight ( int minh)

Definition at line 4121 of file qwidget.cpp.

References d, minimumSize, setMinimumSize(), Qt::Vertical, and width.

Referenced by QtPrivate::QColorShower::QColorShower(), and QWizardPrivate::recreateLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setMinimumSize() [1/2]

void QWidget::setMinimumSize ( const QSize & s)
inline

Definition at line 832 of file qwidget.h.

Referenced by FinalWidget::FinalWidget(), QPagePreview::QPagePreview(), QSystemTrayIconSys::QSystemTrayIconSys(), ScreenWidget::ScreenWidget(), setFixedHeight(), setFixedWidth(), QToolBar::setIconSize(), setMinimumHeight(), setMinimumWidth(), QToolBar::setToolButtonStyle(), QWizardHeader::setup(), and QMdiSubWindow::showShaded().

+ Here is the caller graph for this function:

◆ setMinimumSize() [2/2]

void QWidget::setMinimumSize ( int minw,
int minh )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This function corresponds to setMinimumSize(QSize(minw, minh)).

Sets the minimum width to minw and the minimum height to minh.

Definition at line 3945 of file qwidget.cpp.

References d, height, isMaximized(), isWindow(), maximized, qMax(), resize(), setAttribute(), testAttribute(), Qt::WA_Resized, width, and Qt::WindowMaximized.

+ Here is the call graph for this function:

◆ setMinimumWidth()

void QWidget::setMinimumWidth ( int minw)

Definition at line 4112 of file qwidget.cpp.

References d, height, Qt::Horizontal, minimumSize, and setMinimumSize().

Referenced by QtPrivate::QColorShower::QColorShower(), QWidgetPlatformMenu::setMinimumWidth(), and QPrintPreviewDialogPrivate::updatePageNumLabel().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setMouseTracking()

void QWidget::setMouseTracking ( bool enable)
inline

Definition at line 853 of file qwidget.h.

References setAttribute(), and Qt::WA_MouseTracking.

Referenced by QMdi::ControllerWidget::ControllerWidget(), QSystemTrayIconSys::QSystemTrayIconSys(), QTipLabel::QTipLabel(), QWhatsThat::QWhatsThat(), QWidgetResizeHandler::QWidgetResizeHandler(), QMenuPrivate::ScrollerTearOffItem::ScrollerTearOffItem(), QMenu::changeEvent(), QMenuBar::changeEvent(), QLabel::setText(), and QGraphicsView::setupViewport().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setPalette()

void QWidget::setPalette ( const QPalette & palette)

Definition at line 4530 of file qwidget.cpp.

References d, palette, QPalette::resolve(), QPalette::resolveMask(), setAttribute(), and Qt::WA_SetPalette.

Referenced by QTipLabel::QTipLabel(), QWhatsThat::QWhatsThat(), ScreenWidget::ScreenWidget(), QFocusFrame::eventFilter(), QtPrivate::QCalToolButton::paintEvent(), QWindows11Style::polish(), QWindowsVistaStyle::polish(), QPixmapStyle::polish(), QWizardPrivate::recreateLayout(), ScreenWidget::setColor(), QWizardPrivate::updatePalette(), and QComboBoxPrivate::updateViewContainerPaletteAndOpacity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setParent() [1/2]

void QWidget::setParent ( QWidget * parent)

Sets the parent of the widget to parent, and resets the window flags.

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

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

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

If the "new" parent widget is the old parent widget, this function does nothing.

Note
The widget becomes invisible as part of changing its parent, even if it was previously visible. You must call show() to make the widget visible again.
Warning
It is very unlikely that you will ever need this function. If you have a widget that changes its content dynamically, it is far easier to use \l QStackedWidget.
See also
setWindowFlags()

Definition at line 10599 of file qwidget.cpp.

References QObject::parent(), parentWidget(), setParent(), windowFlags(), and Qt::WindowType_Mask.

Referenced by QTornOffMenu::QTornOffMenu(), QDialogButtonBox::addButton(), QWidgetPrivate::create(), QQuickDialogButtonBoxPrivate::createStandardButton(), createWindowContainer(), QSplitterPrivate::insertWidget_helper(), QDialog::open(), QMdiSubWindowPrivate::removeBaseWidget(), QDialogButtonBoxPrivate::removeButton(), QLayoutPrivate::reparentChildWidgets(), QSplitter::replaceWidget(), QDockAreaLayout::restoreDockWidget(), QWizard::setButton(), QTabWidget::setCornerWidget(), QAbstractItemView::setIndexWidget(), setParent(), QTabBar::setTabButton(), MyScrollArea::setWidget(), QMdiSubWindow::setWidget(), QScrollArea::setWidget(), QWidgetPrivate::setWidgetParentHelper(), QMessageBox::setWindowModality(), and QScrollArea::takeWidget().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setParent() [2/2]

void QWidget::setParent ( QWidget * parent,
Qt::WindowFlags f )

◆ setScreen()

void QWidget::setScreen ( QScreen * screen)

Sets the screen on which the widget should be shown to screen.

Setting the screen only makes sense for windows. If necessary, the widget's window will get recreated on screen.

Note
If the screen is part of a virtual desktop of multiple screens, the window will not move automatically to screen. To place the window relative to the screen, use the screen's topLeft() position.
See also
QWindow::setScreen()

Definition at line 2524 of file qwidget.cpp.

References d, and screen().

Referenced by QDialog::adjustPosition(), and QWidgetPrivate::create().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setShortcutAutoRepeat()

void QWidget::setShortcutAutoRepeat ( int id,
bool enable = true )
Since
4.2

If enable is true, auto repeat of the shortcut with the given id is enabled; otherwise it is disabled.

See also
grabShortcut(), releaseShortcut()

Definition at line 11864 of file qwidget.cpp.

References QGuiApplicationPrivate::instance(), Q_ASSERT, and qApp.

+ Here is the call graph for this function:

◆ setShortcutEnabled()

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

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

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

Definition at line 11849 of file qwidget.cpp.

References QGuiApplicationPrivate::instance(), Q_ASSERT, and qApp.

Referenced by QTabBar::setTabEnabled(), QTabBar::setTabText(), and QTabBar::setTabVisible().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSizeIncrement() [1/2]

void QWidget::setSizeIncrement ( const QSize & s)
inline

Definition at line 838 of file qwidget.h.

◆ setSizeIncrement() [2/2]

void QWidget::setSizeIncrement ( int w,
int h )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the x (width) size increment to w and the y (height) size increment to h.

Definition at line 4035 of file qwidget.cpp.

References d, QTLWExtra::incw, and isWindow().

+ Here is the call graph for this function:

◆ setSizePolicy() [1/2]

◆ setSizePolicy() [2/2]

void QWidget::setSizePolicy ( QSizePolicy::Policy horizontal,
QSizePolicy::Policy vertical )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the size policy of the widget to horizontal and vertical, with standard stretch and no height-for-width.

See also
QSizePolicy::QSizePolicy()

Definition at line 907 of file qwidget.h.

References setSizePolicy().

+ Here is the call graph for this function:

◆ setStyle()

void QWidget::setStyle ( QStyle * style)

Sets the widget's GUI style to style.

The ownership of the style object is not transferred.

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

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

Warning
This function is particularly useful for demonstration purposes, where you want to show Qt's styling capabilities. Real applications should avoid it and use one consistent GUI style instead.
Qt style sheets are currently not supported for custom QStyle subclasses. We plan to address this in some future release.
See also
style(), QStyle, QApplication::style(), QApplication::setStyle()

Definition at line 2630 of file qwidget.cpp.

References d, qApp, QStyleSheetStyle, qt_styleSheet(), setAttribute(), style(), and Qt::WA_SetStyle.

Referenced by QTornOffMenu::QTornOffMenu(), QDialogButtonBoxPrivate::createButton(), QWizardPrivate::ensureButton(), and QWizardPrivate::setStyle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setStyleSheet

void QWidget::setStyleSheet ( const QString & styleSheet)
slot

Definition at line 2555 of file qwidget.cpp.

References child, d, QString::isEmpty(), proxy, QStyleSheetStyle, qt_styleSheet(), styleSheet, testAttribute(), and Qt::WA_SetStyle.

Referenced by QTornOffMenu::QTornOffMenu().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTabletTracking()

void QWidget::setTabletTracking ( bool enable)
inline

Definition at line 862 of file qwidget.h.

References setAttribute(), and Qt::WA_TabletTracking.

+ Here is the call graph for this function:

◆ setTabOrder() [1/2]

void QWidget::setTabOrder ( QWidget * first,
QWidget * second )
static

Puts the second widget after the first widget in the focus order.

It effectively removes the second widget from its focus chain and inserts it after the first widget.

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

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

not like this:

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

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

Note
Since Qt 5.10: A widget that has a child as focus proxy is understood as a compound widget. When setting a tab order between one or two compound widgets, the local tab order inside each will be preserved. This means that if both widgets are compound widgets, the resulting tab order will be from the last child inside first, to the first child inside second.
See also
setFocusPolicy(), setFocusProxy(), {Keyboard Focus in Widgets}

Definition at line 6978 of file qwidget.cpp.

References focusPolicy, focusProxy(), QWidgetPrivate::insertIntoFocusChain(), isAncestorOf(), QWidgetPrivate::Next, nextInFocusChain(), Qt::NoFocus, previousInFocusChain(), Q_UNLIKELY, qobject_cast< QWidget * >(), qWarning, QWidgetPrivate::takeFromFocusChain(), and window().

Referenced by QAbstractItemViewPrivate::editor(), QDialogButtonBoxPrivate::layoutButtons(), QWizardPrivate::setButtonLayout(), and setTabOrder().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTabOrder() [2/2]

void QWidget::setTabOrder ( std::initializer_list< QWidget * > widgets)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
6.6

Sets the tab order for the widgets in the widgets list by calling \l{QWidget::setTabOrder(QWidget *, QWidget *)} for each consecutive pair of widgets.

Instead of setting up each pair manually like this:

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

you can call:

The call does not create a closed tab focus loop. If there are more widgets with \l{Qt::TabFocus} focus policy, tabbing on {d} will move focus to one of those widgets, not back to {a}.

See also
setFocusPolicy(), setFocusProxy(), {Keyboard Focus in Widgets}

Definition at line 7044 of file qwidget.cpp.

References setTabOrder(), widget, and widgets.

+ Here is the call graph for this function:

◆ setUpdatesEnabled()

void QWidget::setUpdatesEnabled ( bool enable)

Definition at line 7851 of file qwidget.cpp.

References d, setAttribute(), and Qt::WA_ForceUpdatesDisabled.

Referenced by QComboBox::showPopup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setVisible

◆ setWindowFilePath()

void QWidget::setWindowFilePath ( const QString & filePath)

Definition at line 6247 of file qwidget.cpp.

References d, and windowFilePath.

◆ setWindowFlag()

void QWidget::setWindowFlag ( Qt::WindowType flag,
bool on = true )
Since
5.9

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

See also
setWindowFlags(), windowFlags(), windowType()

Definition at line 10511 of file qwidget.cpp.

References d.

Referenced by QWindows11Style::polish().

+ Here is the caller graph for this function:

◆ setWindowFlags()

void QWidget::setWindowFlags ( Qt::WindowFlags type)

Definition at line 10497 of file qwidget.cpp.

References d.

Referenced by QRubberBand::changeEvent(), QVideoWidget::setFullScreen(), and QWidgetPlatformDialog::show().

+ Here is the caller graph for this function:

◆ setWindowIcon()

void QWidget::setWindowIcon ( const QIcon & icon)

Definition at line 6171 of file qwidget.cpp.

References d, emit, icon, QIcon::isNull(), setAttribute(), Qt::WA_SetWindowIcon, and windowIconChanged().

Referenced by QMdi::ControlContainer::ControlContainer(), QMdiSubWindow::setWidget(), and QMdi::ControlContainer::updateWindowIcon().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setWindowIconText()

void QWidget::setWindowIconText ( const QString & iconText)

Definition at line 6078 of file qwidget.cpp.

References d, emit, QEvent::IconTextChange, QCoreApplication::sendEvent(), windowIconText, and windowIconTextChanged().

+ Here is the call graph for this function:

◆ setWindowModality()

void QWidget::setWindowModality ( Qt::WindowModality windowModality)

Definition at line 2799 of file qwidget.cpp.

References Qt::NonModal, setAttribute(), Qt::WA_SetWindowModality, Qt::WA_ShowModal, and windowModality.

Referenced by QErrorMessage::QErrorMessage(), moo(), QDialog::open(), QMessageBox::setWindowModality(), and QWidgetPlatformDialog::show().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setWindowModified

void QWidget::setWindowModified ( bool mod)
slot

Definition at line 11581 of file qwidget.cpp.

References d, QEvent::ModifiedChange, QCoreApplication::sendEvent(), setAttribute(), and Qt::WA_WindowModified.

Referenced by QMdiSubWindow::event(), QMdiSubWindow::eventFilter(), and QMdiSubWindow::setWidget().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setWindowOpacity()

void QWidget::setWindowOpacity ( qreal level)

Definition at line 11518 of file qwidget.cpp.

References d, isWindow(), QGraphicsItem::NoCache, QTLWExtra::opacity, proxy, qBound(), scene, setAttribute(), testAttribute(), QGraphicsScene::update(), Qt::WA_WState_Created, and Qt::WA_WState_WindowOpacitySet.

Referenced by QTipLabel::QTipLabel(), QAlphaWidget::~QAlphaWidget(), QWindowsVistaStyle::polish(), QAlphaWidget::render(), QAlphaWidget::run(), QMacStyle::unpolish(), QWindowsVistaStyle::unpolish(), and QComboBoxPrivate::updateViewContainerPaletteAndOpacity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setWindowRole()

void QWidget::setWindowRole ( const QString & role)

Sets the window's role to role.

This only makes sense for windows on X11.

Definition at line 6301 of file qwidget.cpp.

References d, Q_UNUSED, and windowHandle().

Referenced by QWidgetPrivate::create().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setWindowState()

void QWidget::setWindowState ( Qt::WindowStates windowState)

Sets the window state to windowState.

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

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

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

Calling this function will hide the widget. You must call show() to make the widget visible again.

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

When the window state changes, the widget receives a changeEvent() of type QEvent::WindowStateChange.

See also
Qt::WindowState, windowState()

Definition at line 2937 of file qwidget.cpp.

References activateWindow(), adjustSize(), create(), d, geometry, isVisible(), isWindow(), Q_ASSERT, QCoreApplication::sendEvent(), testAttribute(), Qt::WA_Resized, Qt::WA_WState_Created, Qt::WindowActive, Qt::WindowFullScreen, windowHandle(), Qt::WindowMaximized, Qt::WindowMinimized, and windowState().

Referenced by QDockAreaLayout::restoreDockWidget(), restoreGeometry(), QDialog::showEvent(), showFullScreen(), showMaximized(), showMinimized(), and showNormal().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setWindowTitle

◆ sharedPainter()

QPainter * QWidget::sharedPainter ( ) const
overrideprotectedvirtual

A painter that is shared among other instances of QPainter.

Reimplemented from QPaintDevice.

Definition at line 12975 of file qwidget.cpp.

References sp.

◆ show

void QWidget::show ( )
slot

Shows the widget and its child widgets.

For child windows, this is equivalent to calling setVisible(true). Otherwise, it is equivalent to calling showFullScreen(), showMaximized(), or setVisible(true), depending on the platform's default behavior for the window flags.

See also
raise(), showEvent(), hide(), setVisible(), showMinimized(), showMaximized(), showNormal(), isVisible(), windowFlags()

Definition at line 7868 of file qwidget.cpp.

References isWindow(), QGuiApplicationPrivate::platformIntegration(), setVisible(), showFullScreen(), showMaximized(), Qt::WindowFullScreen, and Qt::WindowMaximized.

Referenced by QCalendarWidgetPrivate::_q_yearClicked(), QCalendarWidgetPrivate::_q_yearEditingFinished(), QMessageBox::about(), QMessageBox::aboutQt(), QDialogButtonBoxPrivate::addButtonsToLayout(), addingSubWindowsExample(), camera_blah(), QSplitter::childEvent(), QErrorMessage::done(), QWizardPrivate::enableUpdates(), QInputDialogPrivate::ensureLayout(), QFocusFrame::eventFilter(), QMdiSubWindow::eventFilter(), QDialog::exec(), EditorWindow::find(), QProgressDialog::forceShow(), QFileDialog::getOpenFileContent(), QStatusBar::insertPermanentWidget(), QSplitterPrivate::insertWidget(), QStatusBar::insertWidget(), QSplitterPrivate::insertWidget_helper(), Window::invokableMethod(), QDialogButtonBoxPrivate::layoutButtons(), QTabBarPrivate::layoutTabs(), main(), main(), mainWindowExample(), QMenuPrivate::mouseEventTaken(), Window::normalMethod(), QDialog::open(), overview_viewfinder(), QAlphaWidget::render(), QSplitter::replaceWidget(), QAlphaWidget::run(), QRollEffect::run(), QFileDialog::saveFileContent(), QWizardPrivate::setButtonLayout(), QToolBarLayout::setGeometry(), QCalendarWidget::setGridVisible(), QAbstractItemView::setIndexWidget(), QInputDialogPrivate::setInputWidget(), QMdiSubWindowPrivate::setMaximizeMode(), QMdiSubWindowPrivate::setNormalMode(), QTabBar::setTabButton(), QProgressDialog::setValue(), QCalendarWidget::setVerticalHeaderFormat(), QWidgetPlatformDialog::show(), showAllHiddenTopLevelWidgets(), QErrorMessage::showMessage(), QComboBox::showPopup(), QWizardPrivate::switchToPage(), QMenuBarPrivate::updateGeometries(), VideoExample::VideoSurface(), VideoExample::VideoWidget(), and wrapInFunction().

+ Here is the call graph for this function:

◆ showEvent()

void QWidget::showEvent ( QShowEvent * event)
protectedvirtual

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

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

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(), QShowEvent

Reimplemented in QDialog, QRubberBand, QStatusBar, QTabBar, QTabWidget, QQuickWidget, QComboBox, QComboBoxPrivateContainer, QToolBox, QPrintPropertiesDialog, QMessageBox, QProgressDialog, QAbstractSpinBox, QVideoWidget, QMdiSubWindow, and QSizeGrip.

Definition at line 10069 of file qwidget.cpp.

Referenced by event(), QComboBox::showEvent(), QToolBox::showEvent(), QVideoWidget::showEvent(), QMdiSubWindow::showEvent(), and QSizeGrip::showEvent().

+ Here is the caller graph for this function:

◆ showFullScreen

void QWidget::showFullScreen ( )
slot

Shows the widget in full-screen mode.

Calling this function only affects \l{isWindow()}{windows}.

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

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

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

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

On macOS, showing a window full screen puts the entire application in full-screen mode, providing it with a dedicated desktop. Showing another window while the application runs in full-screen mode might automatically make that window full screen as well. To prevent that, exit full-screen mode by calling showNormal() or by close() on the full screen window before showing another window.

See also
showNormal(), showMaximized(), show(), isVisible(), close()

Definition at line 3021 of file qwidget.cpp.

References activateWindow(), ensurePolished(), setVisible(), setWindowState(), Qt::WindowFullScreen, Qt::WindowMaximized, Qt::WindowMinimized, and windowState().

Referenced by QVideoWidget::setFullScreen(), and show().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showMaximized

void QWidget::showMaximized ( )
slot

Shows the widget maximized.

Calling this function only affects \l{isWindow()}{windows}.

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

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

Definition at line 3044 of file qwidget.cpp.

References ensurePolished(), setVisible(), setWindowState(), Qt::WindowFullScreen, Qt::WindowMaximized, Qt::WindowMinimized, and windowState().

Referenced by QMdiAreaPrivate::emitWindowActivated(), QMdiSubWindow::event(), QMdiSubWindow::eventFilter(), QMdiSubWindow::mouseDoubleClickEvent(), QMdiAreaPrivate::setViewMode(), and show().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showMinimized

void QWidget::showMinimized ( )
slot

Shows the widget minimized, as an icon.

Calling this function only affects \l{isWindow()}{windows}.

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

Definition at line 2847 of file qwidget.cpp.

References ensurePolished(), isMinimized(), isVisible(), setVisible(), setWindowState(), Qt::WindowActive, Qt::WindowMinimized, and windowState().

Referenced by QMdiSubWindow::event(), and QMdiSubWindow::eventFilter().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showNormal

void QWidget::showNormal ( )
slot

Restores the widget after it has been maximized or minimized.

Calling this function only affects \l{isWindow()}{windows}.

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

Definition at line 3060 of file qwidget.cpp.

References ensurePolished(), setVisible(), setWindowState(), Qt::WindowFullScreen, Qt::WindowMaximized, Qt::WindowMinimized, and windowState().

Referenced by QMdiSubWindow::event(), QMdiSubWindow::eventFilter(), QMdiSubWindow::mouseDoubleClickEvent(), QVideoWidget::setFullScreen(), and QMdiAreaPrivate::setViewMode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ size()

QSize QWidget::size ( ) const
inline

Definition at line 895 of file qwidget.h.

◆ sizeHint()

◆ sizeIncrement()

QSize QWidget::sizeIncrement ( ) const

Definition at line 3853 of file qwidget.cpp.

References d.

◆ sizePolicy()

QSizePolicy QWidget::sizePolicy ( ) const

Definition at line 10318 of file qwidget.cpp.

References d.

◆ stackUnder()

void QWidget::stackUnder ( QWidget * w)

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

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

See also
raise(), lower()

Definition at line 11995 of file qwidget.cpp.

References create(), d, isWindow(), parentWidget(), Q_ASSERT, QCoreApplication::sendEvent(), testAttribute(), Qt::WA_WState_Created, and QEvent::ZOrderChange.

Referenced by QFocusFrame::eventFilter(), and QMdiAreaPrivate::internalRaise().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ style()

QStyle * QWidget::style ( ) const
See also
QWidget::setStyle(), QApplication::setStyle(), QApplication::style()

Definition at line 2600 of file qwidget.cpp.

References d, and QApplication::style().

Referenced by QComboBoxPrivateContainer::QComboBoxPrivateContainer(), QDockAreaLayout::QDockAreaLayout(), QErrorMessage::QErrorMessage(), QMenuBarExtension::QMenuBarExtension(), QTipLabel::QTipLabel(), QTornOffMenu::QTornOffMenu(), QWidgetAnimator::animate(), QLineEdit::changeEvent(), QMenu::changeEvent(), QMenuBar::changeEvent(), QTabBar::changeEvent(), QToolButton::changeEvent(), QMessageBox::changeEvent(), QAbstractSpinBox::changeEvent(), QDialogButtonBox::changeEvent(), QScrollBar::contextMenuEvent(), QItemDelegate::doCheck(), QItemDelegate::doLayout(), QItemDelegate::drawCheck(), QMacStyle::drawComplexControl(), QCommonStyle::drawControl(), QItemDelegate::drawDisplay(), QItemDelegate::drawFocus(), QFrame::drawFrame(), QStyledItemDelegate::editorEvent(), QLineEdit::event(), QMenu::event(), QTabBar::event(), QWizard::event(), event(), QGroupBox::event(), QMdiSubWindow::event(), QScrollBar::event(), QToolBar::event(), QFocusFrame::eventFilter(), QMenuBar::eventFilter(), QFontDialog::eventFilter(), QLineEdit::focusInEvent(), QWidgetTextControl::getPaintContext(), QSplitter::handleWidth(), QTabWidget::heightForWidth(), QMenuBar::heightForWidth(), QMenuPrivate::hideMenu(), QComboBox::hidePopup(), QRadioButton::hitButton(), QCheckBox::hitButton(), QPushButton::hitButton(), QAbstractButton::iconSize(), QComboBox::iconSize(), QTabBar::iconSize(), QMenuSloppyState::initialize(), QLineEdit::initStyleOption(), QGroupBox::initStyleOption(), QScrollBar::initStyleOption(), QAbstractSpinBox::initStyleOption(), QTabBar::initStyleOption(), QTabWidget::initStyleOption(), QToolBar::initStyleOption(), QToolButton::initStyleOption(), QTabBar::insertTab(), isActiveWindow(), QMenu::keyPressEvent(), QMenuBar::keyPressEvent(), QAbstractSpinBox::keyPressEvent(), QAbstractSpinBox::minimumSizeHint(), QCalendarWidget::minimumSizeHint(), QGroupBox::minimumSizeHint(), QLineEdit::minimumSizeHint(), QMdiSubWindow::minimumSizeHint(), QMenuBar::minimumSizeHint(), QSlider::minimumSizeHint(), QTabWidget::minimumSizeHint(), QToolBoxButton::minimumSizeHint(), QScrollBar::mouseMoveEvent(), QGroupBox::mouseMoveEvent(), QMdiSubWindow::mouseMoveEvent(), QScrollBar::mousePressEvent(), QTabBar::mousePressEvent(), QToolButton::mousePressEvent(), QComboBoxPrivateContainer::mousePressEvent(), QSlider::mousePressEvent(), QGroupBox::mousePressEvent(), QTabBar::mouseReleaseEvent(), QSlider::mouseReleaseEvent(), QGroupBox::mouseReleaseEvent(), QSplitter::opaqueResize(), QStyledItemDelegate::paint(), QtPrivate::QWellArray::paintCell(), QFileDialogComboBox::paintEvent(), MyPushButton::paintEvent(), QComboBoxPrivateScroller::paintEvent(), QCommandLinkButton::paintEvent(), QFocusFrame::paintEvent(), QLabel::paintEvent(), QLineEdit::paintEvent(), QMenu::paintEvent(), QMenuBar::paintEvent(), QSplitterHandle::paintEvent(), QStatusBar::paintEvent(), QTabBar::paintEvent(), QToolBarSeparator::paintEvent(), QToolBoxButton::paintEvent(), QComboBoxListView::paintEvent(), QComboBoxPrivateContainer::paintEvent(), MyWidget::paintEvent(), QColumnViewGrip::paintEvent(), QDockWidgetTitleButton::paintEvent(), QMdi::ControllerWidget::paintEvent(), QToolBar::paintEvent(), QSvgWidget::paintEvent(), QMdiSubWindow::paintEvent(), QMacStyle::pixelMetric(), QMainWindowLayout::plug(), qSmartSpacing(), qt_setWindowTitle_helperHelper(), QMdi::SimpleCascader::rearrange(), QMenuPrivate::rect(), QGraphicsProxyWidgetPrivate::removeSubFocusHelper(), QTipLabel::resizeEvent(), QComboBoxPrivateContainer::resizeEvent(), QMdiAreaPrivate::resizeToMinimumTileSize(), QLineEdit::setCursorMoveStyle(), QComboBox::setEditable(), setFont(), QFrame::setFrameStyle(), QMainWindow::setIconSize(), QToolBar::setIconSize(), QMessageBox::setInformativeText(), QComboBoxPrivateContainer::setItemView(), QAbstractSpinBox::setLineEdit(), QToolBarExtension::setOrientation(), QLineEdit::setSelection(), setStyle(), QTabBar::setTabsClosable(), QToolButton::setToolButtonStyle(), QFormLayoutPrivate::setupVerticalLayoutData(), QFocusFrame::setWidget(), QGraphicsProxyWidgetPrivate::setWidget_helper(), QWizard::setWizardStyle(), QMdiSubWindow::showEvent(), QComboBox::showPopup(), DetailButton::sizeHint(), QProgressDialog::sizeHint(), QAbstractSpinBox::sizeHint(), QCheckBox::sizeHint(), QComboBoxPrivateScroller::sizeHint(), QDateTimeEdit::sizeHint(), QDockWidgetTitleButton::sizeHint(), QLineEdit::sizeHint(), QMdi::ControllerWidget::sizeHint(), QMenu::sizeHint(), QMenuBarExtension::sizeHint(), QMenuBar::sizeHint(), QProgressBar::sizeHint(), QPushButton::sizeHint(), QRadioButton::sizeHint(), QScrollBar::sizeHint(), QSizeGrip::sizeHint(), QSlider::sizeHint(), QSplitterHandle::sizeHint(), QTabWidget::sizeHint(), QToolBarExtension::sizeHint(), QToolBarSeparator::sizeHint(), QToolBoxButton::sizeHint(), QToolButton::sizeHint(), QStyledItemDelegate::sizeHint(), QAbstractSpinBox::stepBy(), QDockAreaLayout::styleChangedEvent(), QCommonStyle::subElementRect(), QTabBar::tabSizeHint(), QMenuPrivate::updateActionRects(), QStyledItemDelegate::updateEditorGeometry(), QComboBoxPrivateContainer::updateScrollers(), QComboBoxPrivateContainer::updateStyleSettings(), and QComboBoxPrivateContainer::updateTopBottomMargin().

+ Here is the call graph for this function:

◆ styleSheet()

QString QWidget::styleSheet ( ) const

Definition at line 2547 of file qwidget.cpp.

References d.

◆ testAttribute()

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

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

See also
setAttribute()

Definition at line 910 of file qwidget.h.

Referenced by QRollEffect::QRollEffect(), ~QWidget(), acceptDrops(), QWidgetRepaintManager::addStaticWidget(), changeEvent(), QComboBox::changeEvent(), clearFocus(), QMdiSubWindow::closeEvent(), QApplicationPrivate::closePopup(), contentsMargins(), QWidgetPrivate::create(), create(), cursor(), destroy(), QApplicationPrivate::dispatchEnterLeave(), QMacStyle::drawComplexControl(), QWindows11Style::drawComplexControl(), QWindowsVistaStyle::drawComplexControl(), QCommonStyle::drawControl(), effectiveWinId(), QApplication::event(), QMacStyle::event(), event(), QMdiSubWindow::event(), QWhatsThisPrivate::eventFilter(), QDialog::exec(), focusOutEvent(), QApplication::font(), QWidgetItem::geometry(), QSplitterLayoutStruct::getWidgetSize(), grab(), grabForPopup(), QWidgetWindow::handleExposeEvent(), QWidgetWindow::handleMoveEvent(), QWidgetWindow::handleResizeEvent(), QWidgetItem::heightForWidth(), QWidgetPrivate::hideChildren(), QRadioButton::initStyleOption(), QCheckBox::initStyleOption(), isEnabledTo(), isWindowModified(), QMdiAreaPrivate::lastWindowAboutToBeDestroyed(), layoutDirection(), lower(), QWidgetItem::maximumSize(), QWidgetItem::minimumHeightForWidth(), QWidgetItem::minimumSize(), QCheckBox::mouseMoveEvent(), QPushButton::mouseMoveEvent(), QRadioButton::mouseMoveEvent(), QSizeGrip::mouseMoveEvent(), QWidgetResizeHandler::mouseMoveEvent(), QSizeGrip::mousePressEvent(), move(), QDialog::open(), QTipLabel::placeTip(), QWindows11Style::polish(), QWidgetPrivate::prepareToRender(), q_createNativeChildrenAndSetParent(), raise(), resize(), QWidgetPrivate::safeAreaMargins(), setAttribute(), QComboBox::setEditable(), QWidgetPrivate::setEnabled_helper(), setFocus(), QFrame::setFrameStyle(), setGeometry(), QWidgetItem::setGeometry(), QGraphicsWidgetPrivate::setLayoutDirection_helper(), setMask(), setMaximumSize(), setMinimumSize(), QAbstractSlider::setOrientation(), QProgressBar::setOrientation(), QSplitter::setOrientation(), setParent(), QGraphicsScene::setStyle(), setStyleSheet(), setVisible(), QDialog::setVisible(), MyScrollArea::setWidget(), QMdiSubWindow::setWidget(), QScrollArea::setWidget(), setWindowOpacity(), setWindowState(), QWidgetPrivate::showChildren(), QDialog::showEvent(), QComboBox::showPopup(), QMacStyle::sizeFromContents(), QWidgetItem::sizeHint(), stackUnder(), QWidgetRepaintManager::staticContents(), QMacStyle::subControlRect(), QApplicationPrivate::translateRawTouchEvent(), QGraphicsProxyWidgetPrivate::updateProxyInputMethodAcceptanceFromWidget(), QStyleHelper::usePixmapCache(), usePlatformSizeGrip(), QStyleHelper::widgetSizePolicy(), and winId().

◆ topLevelWidget()

QWidget * QWidget::topLevelWidget ( ) const
inline
Deprecated

Use window() instead.

Definition at line 312 of file qwidget.h.

References window().

Referenced by QDockWidgetPrivate::nonClientAreaMouseEvent(), and PressDelayHandler::sendMouseEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ underMouse()

bool QWidget::underMouse ( ) const
inline

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

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

See also
enterEvent(), leaveEvent()

Definition at line 859 of file qwidget.h.

References Qt::WA_UnderMouse.

Referenced by QToolBar::event(), QWidgetWindow::handleEnterLeaveEvent(), QStyleOption::initFrom(), QRadioButton::initStyleOption(), QCheckBox::initStyleOption(), QPushButton::initStyleOption(), QCheckBox::mouseMoveEvent(), QPushButton::mouseMoveEvent(), QRadioButton::mouseMoveEvent(), QCommandLinkButton::paintEvent(), QDockWidgetTitleButton::paintEvent(), and QBalloonTip::timerEvent().

+ Here is the caller graph for this function:

◆ ungrabGesture()

void QWidget::ungrabGesture ( Qt::GestureType gesture)

Unsubscribes the widget from a given gesture type.

See also
grabGesture(), QGestureEvent
Since
4.6

Definition at line 12427 of file qwidget.cpp.

References d, QGestureManager::instance(), and manager.

Referenced by QScroller::ungrabGesture().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unsetCursor()

void QWidget::unsetCursor ( )

Definition at line 4983 of file qwidget.cpp.

References QEvent::CursorChange, d, isWindow(), QCoreApplication::sendEvent(), setAttribute(), and Qt::WA_SetCursor.

Referenced by QToolBar::event(), QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent(), and QGraphicsProxyWidgetPrivate::setWidget_helper().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unsetLayoutDirection()

void QWidget::unsetLayoutDirection ( )

Definition at line 4897 of file qwidget.cpp.

References d, setAttribute(), and Qt::WA_SetLayoutDirection.

Referenced by setLayoutDirection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unsetLocale()

void QWidget::unsetLocale ( )

Definition at line 5936 of file qwidget.cpp.

References d, setAttribute(), and Qt::WA_SetLocale.

+ Here is the call graph for this function:

◆ update [1/4]

void QWidget::update ( )
slot

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

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

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

Qt normally erases the widget's area before the paintEvent() call. If the Qt::WA_OpaquePaintEvent widget attribute is set, the widget is responsible for painting all its pixels with an opaque color.

See also
repaint(), paintEvent(), setUpdatesEnabled(), {Analog Clock}

Definition at line 11167 of file qwidget.cpp.

References rect, and update().

Referenced by QMenu::actionEvent(), QMenuBar::actionEvent(), MyClass::areaEntered(), MyClass::areaExited(), changeEvent(), QLineEdit::changeEvent(), QDockWidget::changeEvent(), QLabelPrivate::ensureTextControl(), QToolButton::enterEvent(), QDockWidgetTitleButton::enterEvent(), QSplitterHandle::event(), QStatusBar::event(), QTabBar::event(), event(), QDockWidget::event(), QGroupBox::event(), QMdiSubWindow::event(), QScrollBar::event(), QAlphaWidget::eventFilter(), QMdiSubWindow::eventFilter(), QLineEdit::focusInEvent(), QComboBox::focusInEvent(), focusInEvent(), QComboBox::focusOutEvent(), focusOutEvent(), QComboBoxPrivateContainer::hideEvent(), QStatusBar::hideOrShow(), QMainWindowLayout::hover(), QLineEditPrivate::init(), QDateTimeEdit::keyPressEvent(), QToolButton::leaveEvent(), QDockWidgetTitleButton::leaveEvent(), QMdi::ControllerWidget::leaveEvent(), QMdiSubWindow::leaveEvent(), QCheckBox::mouseMoveEvent(), QPushButton::mouseMoveEvent(), QRadioButton::mouseMoveEvent(), QScrollBar::mouseMoveEvent(), QTabBar::mouseMoveEvent(), QGroupBox::mouseMoveEvent(), QMdi::ControllerWidget::mouseMoveEvent(), QMdiSubWindow::mouseMoveEvent(), QMenu::mousePressEvent(), QSplitterHandle::mousePressEvent(), QSlider::mousePressEvent(), QGroupBox::mousePressEvent(), QMdi::ControllerWidget::mousePressEvent(), QMdiSubWindow::mousePressEvent(), QSplitterHandle::mouseReleaseEvent(), QTabBar::mouseReleaseEvent(), QSlider::mouseReleaseEvent(), QGroupBox::mouseReleaseEvent(), QMdi::ControllerWidget::mouseReleaseEvent(), QMdiSubWindow::mouseReleaseEvent(), QTabBar::moveTab(), QMenuBarPrivate::popupAction(), QStatusBar::reformat(), QTabBar::removeTab(), ExampleRhiWidget::render(), QProgressBar::resetFormat(), QSystemTrayIconSys::resizeEvent(), QAbstractSpinBox::resizeEvent(), QIconModeViewBase::scrollContentsBy(), QGroupBox::setAlignment(), QLineEdit::setAlignment(), QToolButton::setArrowType(), QPushButton::setAutoDefault(), setAutoFillBackground(), QToolButton::setAutoRaise(), QRhiWidget::setAutoRenderTarget(), QAbstractSpinBox::setButtonSymbols(), QDateTimeEdit::setCalendarPopup(), QGroupBox::setCheckable(), QGroupBox::setChecked(), QRhiWidget::setColorBufferFormat(), QtPrivate::QColorPicker::setCrossVisible(), QMenuPrivate::setCurrentAction(), QTabBar::setCurrentIndex(), QPushButton::setDefault(), QCommandLinkButton::setDescription(), QLCDNumber::setDigitCount(), QTabBar::setDrawBase(), QLineEdit::setEchoMode(), QDockWidget::setFeatures(), QRhiWidget::setFixedColorBufferSize(), QGroupBox::setFlat(), QPushButton::setFlat(), QProgressBar::setFormat(), QAbstractSpinBox::setFrame(), QLineEdit::setFrame(), QFrame::setFrameStyle(), QAbstractButton::setIcon(), QAbstractButton::setIconSize(), QTabBar::setIconSize(), QProgressBar::setInvertedAppearance(), QAbstractSlider::setInvertedAppearance(), QMenuBarPrivate::setKeyboardMode(), QComboBox::setLineEdit(), setMask(), QRhiWidget::setMirrorVertically(), QDial::setNotchesVisible(), QDial::setNotchTarget(), QToolBarSeparator::setOrientation(), QAbstractSlider::setOrientation(), QProgressBar::setOrientation(), QPagePreview::setPageLayout(), QPagePreview::setPagePreviewLayout(), QMovableTabWidget::setPixmap(), QLineEdit::setPlaceholderText(), QComboBox::setPlaceholderText(), QProgressBar::setRange(), QAbstractSpinBox::setReadOnly(), QLineEdit::setReadOnly(), QComboBox::setRootModelIndex(), QRhiWidget::setSampleCount(), QLabel::setScaledContents(), QLCDNumber::setSegmentStyle(), QToolBoxButton::setSelected(), QMenu::setSeparatorsCollapsible(), QAbstractSlider::setSliderPosition(), QLCDNumber::setSmallDecimalPoint(), QTabBar::setTabButton(), QTabBar::setTabEnabled(), QTabBar::setTabIcon(), QTabBar::setTabsClosable(), QTabBar::setTabTextColor(), QTabBar::setTabVisible(), QAbstractButton::setText(), QProgressBar::setTextDirection(), QLineEdit::setTextMargins(), QSlider::setTickInterval(), QSlider::setTickPosition(), QGroupBox::setTitle(), QToolButton::setToolButtonStyle(), QDockWidgetLayout::setVerticalTitleBar(), QFocusFrame::setWidget(), QGraphicsProxyWidgetPrivate::setWidget_helper(), QDial::setWrapping(), QQuickWidget::showEvent(), QComboBoxPrivateContainer::showEvent(), QComboBox::showPopup(), QAbstractSlider::sliderChange(), QComboBoxPrivateContainer::timerEvent(), update(), updateAllWidgets(), QtPrivate::QWellArray::updateCell(), and QSystemTrayIconSys::updateIcon().

+ Here is the call graph for this function:

◆ update() [2/4]

void QWidget::update ( const QRect & rect)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version updates a rectangle rect inside the widget.

Definition at line 11184 of file qwidget.cpp.

References d, and rect.

◆ update() [3/4]

void QWidget::update ( const QRegion & rgn)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version repaints a region rgn inside the widget.

Definition at line 11195 of file qwidget.cpp.

References d.

◆ update() [4/4]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version updates a rectangle (x, y, w, h) inside the widget.

Definition at line 871 of file qwidget.h.

◆ updateGeometry()

void QWidget::updateGeometry ( )

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

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

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

Definition at line 10473 of file qwidget.cpp.

References d.

Referenced by QWindowContainer::QWindowContainer(), changeEvent(), QPushButton::event(), QTabBar::resizeEvent(), QGroupBox::setAlignment(), QToolButton::setArrowType(), QPushButton::setAutoDefault(), QAbstractSpinBox::setButtonSymbols(), QGroupBox::setCheckable(), QCommandLinkButton::setDescription(), QGroupBox::setFlat(), QPushButton::setFlat(), QLineEdit::setFrame(), QAbstractSpinBox::setGroupSeparatorShown(), QAbstractButton::setIcon(), QAbstractButton::setIconSize(), QComboBox::setIconSize(), QTabBar::setIconSize(), QComboBox::setMinimumContentsLength(), QMenuBar::setNativeMenuBar(), QCalendarWidget::setNavigationBarVisible(), QAbstractSlider::setOrientation(), QProgressBar::setOrientation(), QComboBox::setPlaceholderText(), QSpinBox::setPrefix(), QDoubleSpinBox::setPrefix(), QComboBox::setSizeAdjustPolicy(), setSizePolicy(), QSpinBox::setSuffix(), QDoubleSpinBox::setSuffix(), QAbstractButton::setText(), QLineEdit::setTextMargins(), QSlider::setTickPosition(), QGroupBox::setTitle(), QToolButton::setToolButtonStyle(), QWizardHeader::setup(), QWizard::setWizardStyle(), QComboBox::showEvent(), and QComboBoxPrivateContainer::timerEvent().

+ Here is the caller graph for this function:

◆ updateMicroFocus

void QWidget::updateMicroFocus ( Qt::InputMethodQuery query = Qt::ImQueryAll)
protectedslot

Updates the widget's micro focus and informs input methods that the state specified by query has changed.

Definition at line 11876 of file qwidget.cpp.

References QGuiApplication::focusObject(), and QGuiApplication::inputMethod().

Referenced by QLineEdit::focusInEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updatesEnabled()

bool QWidget::updatesEnabled ( ) const
inline

Definition at line 868 of file qwidget.h.

References Qt::WA_UpdatesDisabled.

◆ visibleRegion()

QRegion QWidget::visibleRegion ( ) const

Returns the unobscured region where paint events can occur.

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

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

Definition at line 8660 of file qwidget.cpp.

References d, and QRect::isEmpty().

+ Here is the call graph for this function:

◆ width()

int QWidget::width ( ) const
inline

Definition at line 898 of file qwidget.h.

References QSize::width().

+ Here is the call graph for this function:

◆ window()

QWidget * QWidget::window ( ) const

Returns the window for this widget, i.e.

the next ancestor widget that has (or could have) a window-system frame.

If the widget is a window, the widget itself is returned.

Typical usage is changing the window title:

See also
isWindow()

Definition at line 4313 of file qwidget.cpp.

References parentWidget().

Referenced by ~QWidget(), activateWindow(), QDialog::adjustPosition(), QApplication::alert(), clearFocus(), QQuickControlsTestUtils::clickButton(), QWidgetTextControlPrivate::contextMenuEvent(), correctWidgetContext(), create(), createWindowContainer(), detachWindow(), QWidgetPrivate::determineLastFocusChild(), QApplicationPrivate::dispatchEnterLeave(), QQuickControlsTestUtils::doubleClickButton(), QMacStyle::drawComplexControl(), QApplication::event(), QMenu::event(), QOpenGLWidget::event(), QAbstractButton::event(), QLabel::event(), QWindowContainer::event(), event(), QMdiSubWindow::event(), QCalendarWidget::eventFilter(), QPushButton::focusInEvent(), focusNextPrevChild(), QPushButton::focusOutEvent(), grabKeyboard(), QMenuBarPrivate::handleReparent(), QtWaylandClient::QWaylandInputDevice::handleTouchPoint(), hasFocus(), QWidgetPrivate::hideChildren(), QStyleOption::initFrom(), QOpenGLWidgetPrivate::initialize(), isActiveWindow(), QApplicationPrivate::isBlockedByModal(), QQuickWidgetRenderControlPrivate::isRenderWindow(), QQuickStyleItem::itemChange(), QWidgetRepaintManager::markDirty(), metric(), QOpenGLWidget::metric(), QToolBarPrivate::mouseMoveEvent(), QAbstractButtonPrivate::moveFocus(), QWidgetPrivate::moveRect(), QApplicationPrivate::notify_helper(), QToolBar::paintEvent(), QMacStyle::pixelMetric(), QWidgetPrivate::prepareToRender(), q_createNativeChildrenAndSetParent(), QTest::qWaitForWindowActive(), QTest::qWaitForWindowExposed(), QTest::qWaitForWindowFocused(), releaseKeyboard(), QWidgetPrivate::reparentFocusChildren(), QWidgetPrivate::reparentWidgetWindows(), QWidgetPrivate::safeAreaMargins(), screen(), QWidgetPrivate::scrollRect(), QApplicationPrivate::sendSyntheticEnterLeave(), QApplicationPrivate::setActiveWindow(), QMenuBarPrivate::setCurrentAction(), setFocus(), QMenuBarPrivate::setKeyboardMode(), setParent(), setTabOrder(), QDialogPrivate::setVisible(), QQuickWidget::showEvent(), QComboBox::showPopup(), QQnxScreen::topLevelAt(), QtWaylandClient::QWaylandTouchExtension::touch_extension_touch(), QMenuPrivate::transientParentWindow(), QApplicationPrivate::tryModalHelper(), QQuickControlsTestUtils::verifyButtonClickable(), QSGThreadedRenderLoop::windowDestroyed(), and QtWaylandClient::QWaylandQtKeyExtension::zqt_key_v1_key().

+ Here is the call graph for this function:

◆ windowFilePath()

QString QWidget::windowFilePath ( ) const

Definition at line 6241 of file qwidget.cpp.

References d.

◆ windowFlags()

Qt::WindowFlags QWidget::windowFlags ( ) const
inline

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..
See also
windowType(), setWindowFlag(), {Window Flags Example}

Definition at line 803 of file qwidget.h.

Referenced by QRubberBand::changeEvent(), QMdiSubWindow::event(), QRubberBand::initStyleOption(), QMdiSubWindow::mouseDoubleClickEvent(), QSizeGrip::mousePressEvent(), operator<<(), QMdiSubWindow::paintEvent(), QMacStyle::pixelMetric(), QVideoWidget::setFullScreen(), setParent(), QMdiSubWindow::showEvent(), and QMdiSubWindow::showShaded().

+ Here is the caller graph for this function:

◆ windowHandle()

QWindow * QWidget::windowHandle ( ) const

◆ windowIcon()

QIcon QWidget::windowIcon ( ) const

Definition at line 6132 of file qwidget.cpp.

References d, QWidgetPrivate::extra, and QGuiApplication::windowIcon.

◆ windowIconChanged

void QWidget::windowIconChanged ( const QIcon & icon)
signal

This signal is emitted when the window's icon has changed, with the new icon as an argument.

Since
5.2

Referenced by setWindowIcon().

+ Here is the caller graph for this function:

◆ windowIconText()

QString QWidget::windowIconText ( ) const

Definition at line 6211 of file qwidget.cpp.

References d.

◆ windowIconTextChanged

void QWidget::windowIconTextChanged ( const QString & iconText)
signal

This signal is emitted when the window's icon text has changed, with the new iconText as an argument.

Since
5.2
Deprecated

This signal is deprecated.

Referenced by setWindowIconText().

+ Here is the caller graph for this function:

◆ windowModality()

Qt::WindowModality QWidget::windowModality ( ) const

Definition at line 2794 of file qwidget.cpp.

◆ windowOpacity()

qreal QWidget::windowOpacity ( ) const

Definition at line 11512 of file qwidget.cpp.

References d, and isWindow().

+ Here is the call graph for this function:

◆ windowRole()

QString QWidget::windowRole ( ) const

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

See also
windowIcon, windowTitle

Definition at line 6291 of file qwidget.cpp.

References d.

◆ windowState()

Qt::WindowStates QWidget::windowState ( ) const

◆ windowTitle()

QString QWidget::windowTitle ( ) const

Definition at line 5966 of file qwidget.cpp.

References d, and QFileInfo::fileName().

+ Here is the call graph for this function:

◆ windowTitleChanged

void QWidget::windowTitleChanged ( const QString & title)
signal

This signal is emitted when the window's title has changed, with the new title as an argument.

Since
5.2

Referenced by setWindowTitle().

+ Here is the caller graph for this function:

◆ windowType()

Qt::WindowType QWidget::windowType ( ) const
inline

Returns the window type of this widget.

This is identical to windowFlags() & Qt::WindowType_Mask.

See also
windowFlags

Definition at line 801 of file qwidget.h.

References toInt(), and Qt::WindowType_Mask.

Referenced by changeEvent(), correctWidgetContext(), create(), QApplicationPrivate::desktop(), destroy(), QCoreGraphicsPaintEngine::end(), event(), focusNextPrevChild(), QApplicationPrivate::focusNextPrevChild_helper(), frameGeometry(), frameSize(), QWidgetWindow::handleMouseEvent(), isActiveWindow(), keyPressEvent(), mousePressEvent(), operator<<(), QMacStyle::pixelMetric(), pos(), QMdiAreaPrivate::resizeToMinimumTileSize(), setAttribute(), QGraphicsItemPrivate::setVisibleHelper(), QFocusFrame::setWidget(), x(), and y().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ winId()

WId QWidget::winId ( ) const

Returns the window system identifier of the widget.

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

If a widget is non-native (alien) and winId() is invoked on it, that widget will be provided a native handle.

This value may change at run-time. An event with type QEvent::WinIdChange will be sent to the widget following a change in window system identifier.

See also
find()

Definition at line 2357 of file qwidget.cpp.

References internalWinId(), setAttribute(), testAttribute(), Qt::WA_NativeWindow, and Qt::WA_WState_Created.

Referenced by QWidgetPrivate::create(), event(), q_createNativeChildrenAndSetParent(), QXcbSystemTrayBackingStore::recreateImage(), and QWindowContainerPrivate::updateUsesNativeWidgets().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ x()

int QWidget::x ( ) const

Definition at line 3494 of file qwidget.cpp.

References d, isWindow(), Qt::Popup, and windowType().

+ Here is the call graph for this function:

◆ y()

int QWidget::y ( ) const

Definition at line 3514 of file qwidget.cpp.

References d, isWindow(), Qt::Popup, and windowType().

+ Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ QAccessibleTabButton

friend class QAccessibleTabButton
friend

Definition at line 765 of file qwidget.h.

◆ QAccessibleTable

friend class QAccessibleTable
friend

Definition at line 764 of file qwidget.h.

◆ QAccessibleWidget

friend class QAccessibleWidget
friend

Definition at line 763 of file qwidget.h.

◆ QApplication

friend class QApplication
friend

Definition at line 741 of file qwidget.h.

◆ QApplicationPrivate

friend class QApplicationPrivate
friend

Definition at line 742 of file qwidget.h.

◆ QBackingStoreDevice

friend class QBackingStoreDevice
friend

Definition at line 739 of file qwidget.h.

◆ QBaseApplication

friend class QBaseApplication
friend

Definition at line 745 of file qwidget.h.

◆ QDataWidgetMapperPrivate

friend class QDataWidgetMapperPrivate
friend

Definition at line 725 of file qwidget.h.

◆ QFontInfo

friend class QFontInfo
friend

Definition at line 750 of file qwidget.h.

◆ QFontMetrics

friend class QFontMetrics
friend

Definition at line 749 of file qwidget.h.

Referenced by QDockWidget::paintEvent().

◆ QGestureManager

friend class QGestureManager
friend

Definition at line 767 of file qwidget.h.

◆ QGraphicsProxyWidget

friend class QGraphicsProxyWidget
friend

Definition at line 758 of file qwidget.h.

◆ QGraphicsProxyWidgetPrivate

friend class QGraphicsProxyWidgetPrivate
friend

Definition at line 759 of file qwidget.h.

◆ QGuiApplication

friend class QGuiApplication
friend

Definition at line 743 of file qwidget.h.

◆ QGuiApplicationPrivate

friend class QGuiApplicationPrivate
friend

Definition at line 744 of file qwidget.h.

◆ QLayout

friend class QLayout
friend

Definition at line 751 of file qwidget.h.

◆ QPainter

friend class QPainter
friend

Definition at line 746 of file qwidget.h.

◆ QPainterPrivate

friend class QPainterPrivate
friend

Definition at line 747 of file qwidget.h.

◆ QPixmap

friend class QPixmap
friend

◆ QShortcutPrivate

friend class QShortcutPrivate
friend

Definition at line 756 of file qwidget.h.

◆ QStyleSheetStyle

friend class QStyleSheetStyle
friend

Definition at line 760 of file qwidget.h.

Referenced by setStyle(), and setStyleSheet().

◆ qt_qwidget_data

Q_WIDGETS_EXPORT QWidgetData * qt_qwidget_data ( QWidget * widget)
friend

Definition at line 12376 of file qwidget.cpp.

◆ qt_widget_private

Q_WIDGETS_EXPORT QWidgetPrivate * qt_widget_private ( QWidget * widget)
friend

◆ QWidgetEffectSourcePrivate

friend class QWidgetEffectSourcePrivate
friend

Definition at line 770 of file qwidget.h.

◆ QWidgetExceptionCleaner

friend struct QWidgetExceptionCleaner
friend

Definition at line 761 of file qwidget.h.

◆ QWidgetItem

friend class QWidgetItem
friend

Definition at line 752 of file qwidget.h.

◆ QWidgetItemV2

friend class QWidgetItemV2
friend

Definition at line 753 of file qwidget.h.

◆ QWidgetRepaintManager

friend class QWidgetRepaintManager
friend

Definition at line 740 of file qwidget.h.

Referenced by create().

◆ QWidgetWindow

friend class QWidgetWindow
friend

Definition at line 762 of file qwidget.h.

◆ QWin32PaintEngine

friend class QWin32PaintEngine
friend

Definition at line 755 of file qwidget.h.

◆ QWindowSurface

friend class QWindowSurface
friend

Definition at line 757 of file qwidget.h.

◆ QWinNativePanGestureRecognizer

friend class QWinNativePanGestureRecognizer
friend

Definition at line 768 of file qwidget.h.

◆ QX11PaintEngine

friend class QX11PaintEngine
friend

Definition at line 754 of file qwidget.h.

◆ setupUi()

setupUi ( QWidget * widget)
related

\macro QWIDGETSIZE_MAX

Defines the maximum size for a QWidget object.

The largest allowed size for a widget is QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX), i.e. QSize (16777215,16777215).

See also
QWidget::setMaximumSize()

Sets up the user interface for the specified widget.

Note
This function is available with widgets that derive from user interface descriptions created using \l{uic}.
See also
{Using a Designer UI File in Your Application}

Property Documentation

◆ acceptDrops

QWidget::acceptDrops
readwrite

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.

See also
{Drag and Drop in Qt}{Drag and Drop}

Definition at line 150 of file qwidget.h.

◆ autoFillBackground

QWidget::autoFillBackground
readwrite

whether the widget background is filled automatically

Since
4.1

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 \l{QPalette}{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 \l{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.

See also
Qt::WA_OpaquePaintEvent, Qt::WA_NoSystemBackground, {QWidget::Transparency and Double Buffering}{Transparency and Double Buffering}

Definition at line 172 of file qwidget.h.

Referenced by QMdiSubWindow::paintEvent().

◆ baseSize

QWidget::baseSize
readwrite

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.

See also
setSizeIncrement()

Definition at line 131 of file qwidget.h.

◆ childrenRect

QWidget::childrenRect
read

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.

See also
childrenRegion(), geometry()

Definition at line 117 of file qwidget.h.

◆ childrenRegion

QWidget::childrenRegion
read

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.

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

Definition at line 118 of file qwidget.h.

◆ contextMenuPolicy

QWidget::contextMenuPolicy
readwrite

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.

See also
contextMenuEvent(), customContextMenuRequested(), actions()

Definition at line 142 of file qwidget.h.

◆ cursor

QWidget::cursor
readwrite

the cursor shape for this widget

The mouse cursor will assume this shape when it's over this widget. See the \l{Qt::CursorShape}{list of predefined cursor objects} for a range of useful shapes.

An editor widget might use an I-beam cursor:

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

See also
QGuiApplication::setOverrideCursor()

Definition at line 135 of file qwidget.h.

Referenced by MainWindow::copySelection(), cursor(), MainWindow::cutSelection(), QWidgetResizeHandler::doResize(), QSplashScreen::drawContents(), QLabel::focusOutEvent(), grabMouse(), MainWindow::highlightListItems(), MainWindow::insertCalendar(), MainWindow::insertList(), QWidgetResizeHandler::keyPressEvent(), QMdiSubWindow::keyPressEvent(), QLineEdit::mousePressEvent(), MainWindow::pasteSelection(), QTipLabel::placeTip(), MainWindow::selectBlock(), MainWindow::selectFrame(), MainWindow::selectLine(), MainWindow::selectWord(), setCursor(), QLabel::setSelection(), QGraphicsProxyWidgetPrivate::setWidget_helper(), MainWindow::showList(), MainWindow::showTable(), and MainWindow::updateMenus().

◆ enabled

QWidget::enabled
readwrite

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 \l{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.

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

Definition at line 105 of file qwidget.h.

Referenced by setAutoFillBackground(), QRhiWidget::setAutoRenderTarget(), QTabBar::setDocumentMode(), QTabBar::setExpanding(), QRhiWidget::setMirrorVertically(), QDialog::setSizeGripEnabled(), and QTabBar::setTabEnabled().

◆ focus

QWidget::focus
read

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.
See also
setFocus(), clearFocus(), setFocusPolicy(), QApplication::focusWidget()

Definition at line 141 of file qwidget.h.

◆ focusPolicy

QWidget::focusPolicy
readwrite

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.

See also
focusInEvent(), focusOutEvent(), keyPressEvent(), keyReleaseEvent(), enabled

Definition at line 140 of file qwidget.h.

Referenced by QAbstractButton::animateClick(), QAbstractButton::event(), focusInEvent(), QGroupBox::focusInEvent(), QGraphicsScene::focusNextPrevChild(), QApplicationPrivate::focusNextPrevChild_helper(), focusOutEvent(), iWantTheFocus(), QAbstractButtonPrivate::moveFocus(), QWidgetPrivate::reparentFocusChildren(), QMdiSubWindowPrivate::restoreFocus(), QMenuPrivate::setCurrentAction(), QMdiSubWindowPrivate::setFocusWidget(), setTabOrder(), and QDialogPrivate::setVisible().

◆ font

QWidget::font
readwrite

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 \l styleSheet.

Note
If \l{Qt Style Sheets} are used on the same widget as setFont(), style sheets will take precedence if the settings conflict.
See also
fontInfo(), fontMetrics()

Definition at line 133 of file qwidget.h.

Referenced by QFontComboBox::QFontComboBox(), QWizardHeader::QWizardHeader(), QLabel::changeEvent(), QLineEdit::changeEvent(), QComboBox::changeEvent(), QMessageBox::changeEvent(), QMdiSubWindow::event(), initPainter(), QToolButton::initStyleOption(), QComboBoxListView::initViewItemOption(), QLineEdit::inputMethodQuery(), inputMethodQuery(), QPagePreview::paintEvent(), QDockWidget::paintEvent(), QWindowsVistaStyle::polish(), QFontComboBox::setCurrentFont(), QFontDialog::setCurrentFont(), QFontComboBox::setDisplayFont(), setFont(), QFontComboBox::sizeHint(), QLineEdit::sizeHint(), QWindowsVistaStyle::unpolish(), QFontDialogPrivate::updateSampleFont(), QTipLabel::updateSize(), and src_gui_painting_qpainter2::MyWidget::wrapper15().

◆ frameGeometry

QWidget::frameGeometry
read

geometry of the widget relative to its parent including any window frame

See the \l{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.

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

Definition at line 107 of file qwidget.h.

Referenced by QSizeGrip::mousePressEvent(), QDockWidgetPrivate::nonClientAreaMouseEvent(), operator<<(), and saveGeometry().

◆ frameSize

QWidget::frameSize
read

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.

Definition at line 112 of file qwidget.h.

◆ fullScreen

QWidget::fullScreen
read

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.

See also
windowState(), minimized, maximized

Definition at line 147 of file qwidget.h.

Referenced by restoreGeometry().

◆ geometry

QWidget::geometry
readwrite

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 \l{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.

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

Definition at line 106 of file qwidget.h.

Referenced by QDialog::adjustPosition(), QWidgetAnimator::animate(), QMdiSubWindow::changeEvent(), childWindowAt(), QApplicationPrivate::closePopup(), QWidgetWindowPrivate::closestAcceptableGeometry(), destroy(), dockedGeometry(), droprectangle::Window::dragMoveEvent(), QWindowsVistaStyle::drawPrimitive(), QDockWidget::event(), QAlphaWidget::eventFilter(), QMdiSubWindow::eventFilter(), QPixmapStyle::eventFilter(), QWidgetItem::geometry(), QColorDialogPrivate::handleColorPickingMouseMove(), QWidgetWindow::handleMouseEvent(), QMdiSubWindow::keyPressEvent(), QWidgetResizeHandler::mouseMoveEvent(), QSizeGrip::mousePressEvent(), MainWindow::mousePressEvent(), QMdiSubWindow::mousePressEvent(), QMdiSubWindow::mouseReleaseEvent(), move(), QDockWidgetPrivate::nonClientAreaMouseEvent(), normalGeometry(), operator<<(), operator<<(), QSystemTrayIconSys::paintEvent(), QMenuSloppyState::processMouseEvent(), QSplitter::replaceWidget(), resize(), restoreGeometry(), QAlphaWidget::run(), QRollEffect::run(), saveGeometry(), QToolBarAreaLayout::saveState(), QEvdevTouchScreenData::screenGeometry(), QSplashScreen::setPixmap(), QBoxLayoutPrivate::setupGeom(), setWindowState(), QWizard::setWizardStyle(), QMdiSubWindow::showShaded(), spacingHelper(), QQnxScreen::topLevelAt(), QGraphicsProxyWidgetPrivate::updateProxyGeometryFromWidget(), QMdiAreaPrivate::updateScrollBars(), and QtWaylandClient::QWaylandQtSurface::zqt_shell_surface_v1_set_frame_margins().

◆ height

QWidget::height
read

the height of the widget excluding any window frame

See the \l{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 \l{QScreen::geometry}{screen geometry}.

See also
geometry, width, size

Definition at line 115 of file qwidget.h.

Referenced by QFFmpegVideoBuffer::QFFmpegVideoBuffer(), QRollEffect::QRollEffect(), QCalendarWidgetPrivate::_q_yearClicked(), allocHWFrame(), QWidgetAnimator::animate(), bufferDataSize(), bufferDataSize(), bufferDataSize(), bufferDataSize(), bufferDataSize(), QQuickControlsTestUtils::clickButton(), QSizeGripPrivate::corner(), QWidgetResizeHandler::doResize(), QQuickControlsTestUtils::doubleClickButton(), QWindows11Style::drawPrimitive(), QWindowsVistaStyle::drawPrimitive(), QMainWindowLayoutState::fits(), frameSize(), QDockAreaLayout::gapRect(), QCommandLinkButton::heightForWidth(), QMenuBar::heightForWidth(), QTabWidget::initStyleOption(), inputMethodQuery(), QMenu::keyPressEvent(), mapData(), mapData(), mapData(), mapData(), mapData(), QOpenGLWidget::metric(), minimumHeightForWidth(), QDialog::minimumSizeHint(), QCommandLinkButton::minimumSizeHint(), QProgressBar::minimumSizeHint(), QTabBar::minimumSizeHint(), QWidgetResizeHandler::mouseMoveEvent(), QSizeGrip::mousePressEvent(), move(), QRubberBand::move(), QColumnViewGrip::moveGrip(), QDial::notchSize(), QPagePreview::paintEvent(), QtPrivate::QColorLuminancePicker::paintEvent(), QMenu::paintEvent(), QMenuBar::paintEvent(), plaintextlayout::Window::paintEvent(), QWizardHeader::paintEvent(), QWizard::paintEvent(), SplitterHandle::paintEvent(), QTipLabel::placeTip(), QMdi::IconTiler::rearrange(), QQuickMenuPositioner::reposition(), QtPrivate::QColorPicker::resizeEvent(), QOpenGLWidget::resizeEvent(), QColumnViewPreviewColumn::resizeEvent(), QMdiSubWindow::resizeEvent(), QMdiAreaPrivate::resizeToMinimumTileSize(), QWhatsThisPrivate::say(), QFFmpeg::VideoFrameEncoder::sendFrame(), setFixedWidth(), setMaximumSize(), setMaximumWidth(), setMinimumSize(), setMinimumWidth(), QCompleterPrivate::showPopup(), QDialog::sizeHint(), QMenuBarPrivate::updateGeometries(), QFocusFramePrivate::updateSize(), QScrollAreaPrivate::updateWidgetPosition(), QQuickControlsTestUtils::verifyButtonClickable(), and doc_src_coordsys::SnippetWrappers::wrapper4().

◆ inputMethodHints

QWidget::inputMethodHints
readwrite

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.

Warning
Some widgets require certain flags to work as intended. To set a flag, do {w->setInputMethodHints(w->inputMethodHints()|f)} instead of {w->setInputMethodHints(f)}.
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.

Since
4.6
See also
inputMethodQuery()

Definition at line 178 of file qwidget.h.

Referenced by QInputDialog::getItem(), QInputDialog::getMultiLineText(), QInputDialog::getText(), inputMethodQuery(), QAbstractSpinBox::inputMethodQuery(), QWidgetLineControl::processKeyEvent(), QLineEdit::setEchoMode(), and QGraphicsViewPrivate::updateInputMethodSensitivity().

◆ isActiveWindow

QWidget::isActiveWindow
read

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.

See also
activateWindow(), QApplication::activeWindow()

Definition at line 139 of file qwidget.h.

Referenced by QApplication::alert(), QAbstractSpinBox::changeEvent(), QWindows11Style::drawComplexControl(), QWindowsVistaStyle::drawComplexControl(), isActiveWindow(), and palette().

◆ layoutDirection

QWidget::layoutDirection
readwrite

the layout direction for this widget.

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

See also
QApplication::layoutDirection

Definition at line 170 of file qwidget.h.

Referenced by QToolBarAreaLayout::apply(), QFormLayoutPrivate::arrangeWidgets(), QSplashScreen::drawContents(), QBoxLayoutPrivate::effectiveMargins(), QWizard::event(), QToolBarAreaLayout::gapIndex(), QStyleOption::initFrom(), QToolBarAreaLayout::itemRect(), QLineEdit::mouseMoveEvent(), QLabel::paintEvent(), QMenuSloppyState::processMouseEvent(), QMdi::RegularTiler::rearrange(), QMdi::SimpleCascader::rearrange(), QMdi::IconTiler::rearrange(), QWidgetItem::setGeometry(), QCompleterPrivate::showPopup(), QCommonStyle::subElementRect(), and QTabBar::tabRect().

◆ locale

QWidget::locale
readwrite

the widget's locale

Since
4.3

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.

See also
QLocale, QLocale::setDefault()

Definition at line 176 of file qwidget.h.

Referenced by QCalendarWidget::event(), QSpinBox::fixup(), QDoubleSpinBox::fixup(), QCalendarWidget::minimumSizeHint(), setLocale(), QProgressBar::text(), QDateTimeEdit::textFromDateTime(), QDoubleSpinBox::textFromValue(), and QSpinBox::textFromValue().

◆ maximized

QWidget::maximized
read

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.

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

Definition at line 146 of file qwidget.h.

Referenced by restoreGeometry(), and setMinimumSize().

◆ maximumHeight

QWidget::maximumHeight
readwrite

the widget's maximum height in pixels

This property corresponds to the height held by the \l 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.
See also
maximumSize, maximumWidth

Definition at line 128 of file qwidget.h.

Referenced by QWidgetItem::heightForWidth(), and QWidgetItem::minimumHeightForWidth().

◆ maximumSize

QWidget::maximumSize
readwrite

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.
See also
maximumWidth, maximumHeight, minimumSize, sizeIncrement

Definition at line 121 of file qwidget.h.

Referenced by QTableViewPrivate::heightHintForIndex(), QDockWidgetLayout::maximumSize(), menuBarHeightForWidth(), QWidgetResizeHandler::mouseMoveEvent(), QToolBarAreaLayoutItem::realSizeHint(), resize(), setFixedHeight(), setFixedWidth(), setGeometry(), setMaximumHeight(), setMaximumWidth(), QComboBox::showPopup(), QWidgetItem::sizeHint(), QTableViewPrivate::widthHintForIndex(), and QTreeViewPrivate::widthHintForIndex().

◆ maximumWidth

QWidget::maximumWidth
readwrite

the widget's maximum width in pixels

This property corresponds to the width held by the \l 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.
See also
maximumSize, maximumHeight

Definition at line 126 of file qwidget.h.

Referenced by QWizardPrivate::updateMinMaxSizes().

◆ minimized

QWidget::minimized
read

whether this widget is minimized (iconified)

This property is only relevant for windows.

By default, this property is false.

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

Definition at line 145 of file qwidget.h.

◆ minimumHeight

QWidget::minimumHeight
readwrite

the widget's minimum height in pixels

This property corresponds to the height held by the \l minimumSize property.

By default, this property has a value of 0.

See also
minimumSize, minimumWidth

Definition at line 124 of file qwidget.h.

Referenced by QWidgetItem::heightForWidth(), QWidgetItem::minimumHeightForWidth(), and QCommandLinkButton::minimumSizeHint().

◆ minimumSize

QWidget::minimumSize
readwrite

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. To unset the minimum size, use a value of {QSize(0, 0)}.

By default, this property contains a size with zero width and height.

See also
minimumWidth, minimumHeight, maximumSize, sizeIncrement

Definition at line 120 of file qwidget.h.

Referenced by QTableViewPrivate::heightHintForIndex(), QWidgetResizeHandler::mouseMoveEvent(), QToolBarAreaLayoutItem::realSizeHint(), resize(), setFixedHeight(), setFixedWidth(), setGeometry(), QWidgetItem::setGeometry(), setMinimumHeight(), setMinimumWidth(), QComboBox::showPopup(), QMdiSubWindow::showShaded(), QWidgetItem::sizeHint(), QTableViewPrivate::widthHintForIndex(), and QTreeViewPrivate::widthHintForIndex().

◆ minimumSizeHint

QWidget::minimumSizeHint
read

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

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

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

Definition at line 149 of file qwidget.h.

Referenced by QDialog::minimumSizeHint(), QWatermarkLabel::minimumSizeHint(), QGroupBox::minimumSizeHint(), QToolBarAreaLayoutItem::realSizeHint(), and QWidgetItem::sizeHint().

◆ minimumWidth

QWidget::minimumWidth
readwrite

the widget's minimum width in pixels

This property corresponds to the width held by the \l minimumSize property.

By default, this property has a value of 0.

See also
minimumSize, minimumHeight

Definition at line 122 of file qwidget.h.

Referenced by menuBarHeightForWidth(), QColumnViewGrip::moveGrip(), QColumnViewPreviewColumn::resizeEvent(), and QColumnViewPreviewColumn::setPreviewWidget().

◆ modal

QWidget::modal
read

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.

See also
isWindow(), windowModality, QDialog

Definition at line 103 of file qwidget.h.

◆ mouseTracking

QWidget::mouseTracking
readwrite

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.

See also
mouseMoveEvent()

Definition at line 137 of file qwidget.h.

◆ normalGeometry

QWidget::normalGeometry
read

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.

See also
QWidget::windowState(), QWidget::geometry

Definition at line 108 of file qwidget.h.

Referenced by saveGeometry().

◆ palette

QWidget::palette
readwrite

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 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, and Windows 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 \l {styleSheet}.

Warning
Do not use this function in conjunction with \l{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".
See also
QGuiApplication::palette(), QWidget::font(), {Qt Style Sheets}

Definition at line 132 of file qwidget.h.

Referenced by ScreenWidget::ScreenWidget(), QStyleHelper::backgroundColor(), QLabel::changeEvent(), QLineEdit::changeEvent(), QQC2::QCommonStyle::drawComplexControl(), QMacStyle::drawComplexControl(), QCommonStyle::drawComplexControl(), QAndroidStyle::drawComplexControl(), QAndroidStyle::AndroidControl::drawControl(), QQC2::QCommonStyle::drawControl(), QCommonStyle::drawControl(), QWindowsVistaStyle::drawControl(), QWindows11Style::drawPrimitive(), QWindowsVistaStyle::drawPrimitive(), QQC2::QCommonStyle::drawPrimitive(), QQC2::QWindowsStyle::drawPrimitive(), QAndroidStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), event(), QWidgetTextControl::getPaintContext(), QStyleOption::initFrom(), initPainter(), QMenuBar::initStyleOption(), QMenuBar::minimumSizeHint(), QTabWidget::minimumSizeHint(), QtPrivate::QWellArray::paintCell(), QPagePreview::paintEvent(), QtPrivate::QColorLuminancePicker::paintEvent(), QFileDialogComboBox::paintEvent(), QWhatsThat::paintEvent(), QCommandLinkButton::paintEvent(), QLineEdit::paintEvent(), QMenu::paintEvent(), QMenuBar::paintEvent(), QSplitterHandle::paintEvent(), QStatusBar::paintEvent(), QtPrivate::QCalToolButton::paintEvent(), QComboBox::paintEvent(), QWizardHeader::paintEvent(), MyWidget::paintEvent(), QToolBar::paintEvent(), MyWidget::paintEvent2(), QWindows11Style::polish(), QWindowsVistaStyle::polish(), QPixmapStyle::polish(), QWizardPrivate::recreateLayout(), ScreenWidget::setColor(), QComboBox::setEditable(), setPalette(), QMenuBar::sizeHint(), and QComboBoxPrivate::updateViewContainerPaletteAndOpacity().

◆ pos

QWidget::pos
readwrite

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 \l{Window Geometry} documentation for an overview of geometry issues with windows.

Note
Not all windowing systems support setting or querying top level window positions. On such a system, programmatically moving windows may not have any effect, and artificial values may be returned for the current positions, such as QPoint(0, 0).
See also
frameGeometry, size, x(), y()

Definition at line 111 of file qwidget.h.

Referenced by QTipLabel::QTipLabel(), QSplitterHandle::closestLegalPosition(), QSplitter::closestLegalPosition(), QLineEdit::cursorPositionAt(), QDateTimeEdit::dateTimeFromText(), QFFmpeg::Renderer::doNextStep(), QTabBar::event(), event(), QMainWindow::event(), QToolBar::event(), QMenu::exec(), QMenu::exec(), QTipLabel::getTipScreen(), QRadioButton::hitButton(), QAbstractButton::hitButton(), QCheckBox::hitButton(), QPushButton::hitButton(), QToolButton::hitButton(), QToolButton::initStyleOption(), insertAction(), QMainWindow::isSeparator(), QDateTimeEdit::keyPressEvent(), QMdiSubWindow::keyPressEvent(), mapFrom(), mapFrom(), mapFromGlobal(), mapFromGlobal(), mapFromParent(), mapFromParent(), mapTo(), mapTo(), mapToGlobal(), mapToGlobal(), mapToParent(), mapToParent(), QGraphicsProxyWidgetPrivate::mapToReceiver(), QTabBar::mouseDoubleClickEvent(), QSplitterHandle::mouseMoveEvent(), QTipLabel::mouseMoveEvent(), QComboBoxPrivateScroller::mouseMoveEvent(), QtPrivate::QWellArray::mousePressEvent(), QTabBar::mousePressEvent(), QSplitterHandle::mouseReleaseEvent(), QSplitterHandle::moveSplitter(), QSplitter::moveSplitter(), QTipLabel::placeTip(), QMenuPrivate::popup(), MainWindow::readSettings(), QTipLabel::reuseTip(), QLineEdit::setCursorPosition(), QVideoWidget::setFullScreen(), QSplitter::setRubberBand(), QTabWidget::setTabPosition(), QBalloonTip::showBalloon(), QMenu::showTearOffMenu(), QTipLabel::tipChanged(), QBalloonTip::updateBalloonPosition(), QGraphicsProxyWidgetPrivate::updateProxyGeometryFromWidget(), QTipLabel::updateSize(), QDateTimeEdit::validate(), QSpinBox::validate(), QDoubleSpinBox::validate(), QPdfPageSelectorSpinBox::validate(), QSpinBox::valueFromText(), QDoubleSpinBox::valueFromText(), src_gui_util_qvalidator::Wrapper::wrapper0(), src_gui_util_qvalidator::Wrapper::wrapper1(), src_gui_util_qvalidator::Wrapper::wrapper2(), and MainWindow::writeSettings().

◆ rect

QWidget::rect
read

the internal geometry of the widget excluding any window frame

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

See the \l{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.

See also
size

Definition at line 116 of file qwidget.h.

Referenced by QMenuPrivate::actionAt(), contentsRect(), QDialog::contextMenuEvent(), QWidgetResizeHandler::doResize(), QPixmapStyle::drawCheckBox(), QQC2_NAMESPACE::QMacStyle::drawComplexControl(), QQC2::QCommonStyle::drawComplexControl(), QMacStyle::drawComplexControl(), QCommonStyle::drawComplexControl(), QAndroidStyle::drawComplexControl(), QSplashScreen::drawContents(), QAndroidStyle::AndroidControl::drawControl(), QQC2::QCommonStyle::drawControl(), QCommonStyle::drawControl(), src_gui_image_qicon::MyWidget::drawIcon(), QGraphicsScenePrivate::drawItemHelper(), QWindows11Style::drawPrimitive(), QWindowsVistaStyle::drawPrimitive(), QQC2::QCommonStyle::drawPrimitive(), QQC2::QWindowsStyle::drawPrimitive(), QAndroidStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QQC2::QWindowsXPStyle::drawPrimitive(), QPixmapStyle::drawRadioButton(), QMenuPrivate::drawScroller(), QMenuPrivate::drawTearOff(), QWindowContainer::event(), QGroupBox::event(), QWidgetResizeHandler::eventFilter(), grab(), QWidgetWindow::handleResizeEvent(), QMenuBar::heightForWidth(), QAbstractButton::hitButton(), QStyleOption::initFrom(), QMenuBar::initStyleOption(), QMenuBar::minimumSizeHint(), QCheckBox::mouseMoveEvent(), QMenu::mouseMoveEvent(), QPushButton::mouseMoveEvent(), QScrollBar::mouseMoveEvent(), QWidgetResizeHandler::mouseMoveEvent(), QComboBoxPrivateScroller::mouseMoveEvent(), QWhatsThat::mousePressEvent(), QMenu::mousePressEvent(), QCalendarPopup::mousePressEvent(), mousePressEvent(), QWhatsThat::mouseReleaseEvent(), QLineEdit::mouseReleaseEvent(), QAbstractButtonPrivate::moveFocus(), QComboBoxDelegate::paint(), QtPrivate::QWellArray::paintCell(), QCalendarWidget::paintCell(), QPagePreview::paintEvent(), QtPrivate::QWellArray::paintEvent(), QWhatsThat::paintEvent(), QBalloonTip::paintEvent(), QSystemTrayIconSys::paintEvent(), QComboBoxPrivateScroller::paintEvent(), QFocusFrame::paintEvent(), QMenu::paintEvent(), QMenuBar::paintEvent(), QTabBar::paintEvent(), plaintextlayout::Window::paintEvent(), SplitterHandle::paintEvent(), QQuickWidget::paintEvent(), QMdiSubWindow::paintEvent(), raise(), repaint(), repaint(), QDialog::resizeEvent(), scroll(), scroll(), QApplicationPrivate::sendMouseEvent(), QMenuPrivate::setFirstActionActive(), QFrame::setFrameRect(), setMask(), QDialog::setSizeGripEnabled(), QMenu::sizeHint(), QMenuBar::sizeHint(), QWindowsVistaStyle::styleHint(), QCommonStyle::styleHint(), QQC2_NAMESPACE::QMacStyle::subControlRect(), QQC2::QCommonStyle::subControlRect(), QMacStyle::subControlRect(), QCommonStyle::subControlRect(), QWindows11Style::subControlRect(), QWindowsVistaStyle::subElementRect(), QTabBar::tabRect(), update(), update(), QMenuPrivate::updateActionRects(), widgetRectFor(), src_gui_painting_qpainter2::MyWidget::wrapper11(), and src_gui_painting_qpainter2::MyWidget::wrapper7().

◆ size

QWidget::size
readwrite

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.
See also
pos, geometry, minimumSize, maximumSize, resizeEvent(), adjustSize()

Definition at line 113 of file qwidget.h.

Referenced by QQuickVideoOutput::QQuickVideoOutput(), QSystemTrayIconSys::QSystemTrayIconSys(), _q_boundGeometryToSizeConstraints(), QGraphicsVideoItemPrivate::_q_present(), QDialog::adjustPosition(), QWidgetAnimator::animate(), closestAcceptableSize(), QMacStylePrivate::cocoaCell(), QMacStylePrivate::cocoaControl(), QQuickLabsPlatformMenu::data_count(), QQuickLabsPlatformMenuBar::data_count(), QScrollArea::ensureWidgetVisible(), QOpenGLWidget::event(), QRhiWidget::event(), QToolBarLayout::expandedSize(), findTextureWidgetsRecursively(), QDockAreaLayout::gapRect(), QFileDialog::getOpenFileContent(), QSplitterLayoutStruct::getWidgetSize(), QSystemTrayIconSys::globalGeometry(), QWidgetWindow::handleMouseEvent(), QTabBarPrivate::initBasicStyleOption(), QQuickLabsPlatformMenu::items_count(), mapData(), mapData(), QWidgetRepaintManager::markDirty(), QQuickLabsPlatformMenuBar::menus_count(), QCommandLinkButton::minimumSizeHint(), QProgressBar::minimumSizeHint(), QTabBar::minimumTabSizeHint(), org.qtproject.qt.android.QtActivityBase::onPrepareOptionsMenu(), QSystemTrayIconSys::paintEvent(), QTabBar::paintEvent(), QTabWidget::paintEvent(), QGstreamerImageCapture::probeBuffer(), QFFmpeg::VideoEncoder::processOne(), qImageFromVideoFrame(), qRotatedFrameSize(), QOpenGLWidget::resizeEvent(), QRhiWidget::resizeEvent(), QColumnViewPreviewColumn::resizeEvent(), QMdiAreaPrivate::resizeToMinimumTileSize(), restoreGeometry(), QAlphaWidget::run(), scroll(), scroll(), QTabBar::setCurrentIndex(), QDockWidget::setFloating(), QAbstractButton::setIconSize(), QComboBox::setIconSize(), QTabBar::setIconSize(), QWizard::setWizardStyle(), QMdiSubWindow::showEvent(), QWizard::sizeHint(), QCommandLinkButton::sizeHint(), QMdi::ControllerWidget::sizeHint(), QMdiSubWindow::sizeHint(), QScrollBar::sizeHint(), QQuickWidget::sizeHint(), QVideoWidget::sizeHint(), snippet_ctor2(), QQC2::QCommonStyle::subControlRect(), QCommonStyle::subControlRect(), QGraphicsProxyWidget::subWidgetRect(), QGraphicsProxyWidgetPrivate::updateProxyGeometryFromWidget(), QScrollAreaPrivate::updateScrollBars(), QVideoTextureHelper::updateUniformData(), QScrollAreaPrivate::updateWidgetPosition(), and MainWindow::writeSettings().

◆ sizeHint

◆ sizeIncrement

QWidget::sizeIncrement
readwrite

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.
See also
size, minimumSize, maximumSize

Definition at line 130 of file qwidget.h.

◆ sizePolicy

QWidget::sizePolicy
readwrite

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

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

Definition at line 119 of file qwidget.h.

Referenced by QWidgetItem::controlTypes(), QSplitterPrivate::doResize(), QWidgetItem::expandingDirections(), QSplitterLayoutStruct::getWidgetSize(), QWidgetItem::isEmpty(), QLabel::minimumSizeHint(), QMacStyle::pixelMetric(), QToolBarAreaLayoutItem::realSizeHint(), QWidgetItem::setGeometry(), QAbstractSlider::setOrientation(), QProgressBar::setOrientation(), QSplitter::setOrientation(), QSplitter::setStretchFactor(), QWidgetItem::sizeHint(), QScrollAreaPrivate::updateScrollBars(), and QFormLayoutItem::vStretch().

◆ styleSheet

QWidget::styleSheet
readwrite

the widget's style sheet

Since
4.2

The style sheet contains a textual description of customizations to the widget's style, as described in the \l{Qt Style Sheets} document.

Since Qt 4.5, Qt style sheets fully supports \macos.

Warning
Qt style sheets are currently not supported for custom QStyle subclasses. We plan to address this in some future release.
See also
setStyle(), QApplication::styleSheet, {Qt Style Sheets}

Definition at line 174 of file qwidget.h.

Referenced by setStyleSheet().

◆ tabletTracking

QWidget::tabletTracking
readwrite

whether tablet tracking is enabled for the widget

Since
5.9

If tablet tracking is disabled (the default), the widget only receives tablet move events when the stylus is in contact with the tablet, or at least one stylus button is pressed, while the stylus is being moved.

If tablet tracking is enabled, the widget receives tablet move events even while hovering in proximity. This is useful for monitoring position as well as the auxiliary properties such as rotation and tilt, and providing feedback in the UI.

See also
tabletEvent()

Definition at line 138 of file qwidget.h.

◆ updatesEnabled

QWidget::updatesEnabled
readwrite

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:

QSize size
the size of the widget excluding any window frame
Definition qwidget.h:113
QByteArray saveGeometry() const
Definition qwidget.cpp:7334
@ WindowFullScreen
Definition qnamespace.h:255
@ WindowMinimized
Definition qnamespace.h:253
@ WindowActive
Definition qnamespace.h:256
setUpdatesEnabled(false)
[12]
setCursor(Qt::IBeamCursor)
[3]
QSettings settings("MyCompany", "MyApp")
[11]
setTabOrder(a, b)
[8]
bigVisualChanges()

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.

See also
paintEvent()

Definition at line 143 of file qwidget.h.

Referenced by QWidgetRepaintManager::markDirty(), QWidgetPrivate::moveRect(), QOpenGLWidget::paintEvent(), QRhiWidget::paintEvent(), scroll(), scroll(), and QComboBox::showPopup().

◆ visible

QWidget::visible
readwrite

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

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

Definition at line 144 of file qwidget.h.

Referenced by QMdi::ControllerWidget::setControlVisible(), QtPrivate::QColorPicker::setCrossVisible(), QCalendarWidget::setNavigationBarVisible(), QDial::setNotchesVisible(), QTabBar::setTabVisible(), QTabWidget::setTabVisible(), QProgressBar::setTextVisible(), QMenu::setToolTipsVisible(), setVisible(), QPrintPreviewDialog::setVisible(), QPrintPreviewWidget::setVisible(), QColorDialog::setVisible(), QDialog::setVisible(), QFileDialog::setVisible(), QFontDialog::setVisible(), QInputDialog::setVisible(), QWizard::setVisible(), QMenuBar::setVisible(), and QSizeGrip::setVisible().

◆ width

QWidget::width
read

the width of the widget excluding any window frame

See the \l{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 multi-screen desktop. See QScreen for details.

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

See also
geometry, height, size

Definition at line 114 of file qwidget.h.

Referenced by QFFmpegVideoBuffer::QFFmpegVideoBuffer(), QRollEffect::QRollEffect(), QCalendarWidgetPrivate::_q_yearClicked(), allocHWFrame(), QWidgetAnimator::animate(), QMenuBar::changeEvent(), QQuickControlsTestUtils::clickButton(), QSizeGripPrivate::corner(), QWidgetResizeHandler::doResize(), QQuickControlsTestUtils::doubleClickButton(), QWindows11Style::drawPrimitive(), QFontComboBox::event(), QWizard::event(), QMdiSubWindow::event(), QMdiSubWindow::eventFilter(), QMainWindowLayoutState::fits(), frameSize(), QDockAreaLayout::gapRect(), QTabWidget::initStyleOption(), inputMethodQuery(), QMenu::keyPressEvent(), QMdiSubWindow::leaveEvent(), QStatusBarPrivate::messageRect(), QOpenGLWidget::metric(), minimumHeightForWidth(), QDialog::minimumSizeHint(), QMdiSubWindow::minimumSizeHint(), QMenuBar::minimumSizeHint(), QProgressBar::minimumSizeHint(), QColumnViewGrip::mouseDoubleClickEvent(), QToolBarPrivate::mouseMoveEvent(), QWidgetResizeHandler::mouseMoveEvent(), QMdiSubWindow::mouseMoveEvent(), QSizeGrip::mousePressEvent(), QMdiSubWindow::mousePressEvent(), QMdiSubWindow::mouseReleaseEvent(), move(), QRubberBand::move(), QColumnViewGrip::moveGrip(), QTabBar::moveTab(), QDial::notchSize(), QPagePreview::paintEvent(), QtPrivate::QColorLuminancePicker::paintEvent(), QMenu::paintEvent(), QMenuBar::paintEvent(), plaintextlayout::Window::paintEvent(), QWizardHeader::paintEvent(), SplitterHandle::paintEvent(), QMdiSubWindow::paintEvent(), QTipLabel::placeTip(), QMdi::IconTiler::rearrange(), QXcbSystemTrayBackingStore::recreateImage(), QQuickMenuPositioner::reposition(), QtPrivate::QColorPicker::resizeEvent(), QOpenGLWidget::resizeEvent(), QMdiSubWindow::resizeEvent(), saveGeometry(), QWhatsThisPrivate::say(), QFFmpeg::VideoFrameEncoder::sendFrame(), setFixedHeight(), QSplitter::setHandleWidth(), setMaximumHeight(), setMaximumSize(), setMinimumHeight(), setMinimumSize(), QWizardHeader::setup(), QComboBox::showPopup(), QCompleterPrivate::showPopup(), QDialog::sizeHint(), QMenuBar::sizeHint(), QMenuPrivate::updateActionRects(), QFocusFramePrivate::updateSize(), QScrollAreaPrivate::updateWidgetPosition(), QQuickControlsTestUtils::verifyButtonClickable(), and doc_src_coordsys::SnippetWrappers::wrapper4().

◆ windowFilePath

QWidget::windowFilePath
readwrite

the file path associated with a widget

Since
4.4

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 the file name of the specified path, obtained using QFileInfo::fileName().

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 \macos, this has an added benefit that it sets the \l{http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuidelines/XHIGWindows/chapter_17_section_3.html}{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.

See also
windowTitle, windowIcon

Definition at line 177 of file qwidget.h.

Referenced by setWindowFilePath().

◆ windowIcon

QWidget::windowIcon
readwrite

the widget's icon

This property only makes sense for windows. If no icon has been set, windowIcon() returns the application icon (QApplication::windowIcon()).

Note
On \macos, window icons represent the active document, and will not be displayed unless a file path has also been set using setWindowFilePath.
See also
windowTitle, setWindowFilePath

Definition at line 152 of file qwidget.h.

Referenced by QMdi::ControlContainer::ControlContainer(), QMessageBox::about(), QWindowsVistaStyle::drawControl(), QMdiSubWindow::event(), and QMdiSubWindow::setWidget().

◆ windowIconText

QWidget::windowIconText
readwrite

the text to be displayed on the icon of a minimized window

This property only makes sense for windows. If no icon text has been set, this accessor returns an empty string. It is only implemented on the X11 platform, and only certain window managers use this window property.

Deprecated
This property is deprecated.
See also
windowIcon, windowTitle

Definition at line 153 of file qwidget.h.

Referenced by setWindowIconText().

◆ windowModality

QWidget::windowModality
readwrite

which windows are blocked by the modal widget

Since
4.1

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.

See also
isWindow(), QWidget::modal, QDialog

Definition at line 104 of file qwidget.h.

Referenced by QDialog::open(), QMessageBox::setWindowModality(), and setWindowModality().

◆ windowModified

QWidget::windowModified
readwrite

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

See also
windowTitle

Definition at line 155 of file qwidget.h.

Referenced by QMdiSubWindow::eventFilter().

◆ windowOpacity

QWidget::windowOpacity
readwrite

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, \macos, Windows, and X11 platforms that support the Composite extension.

Note
On 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 QScreen::grabWindow(). Also note that semi-transparent windows update and resize significantly slower than opaque windows.
See also
setMask()

Definition at line 154 of file qwidget.h.

Referenced by QComboBoxPrivate::updateViewContainerPaletteAndOpacity().

◆ windowTitle

QWidget::windowTitle
readwrite

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 \l windowFilePath. If neither of these is set, then the title is an empty string.

If you use the \l 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 \l windowModified property is false (the default), the placeholder is simply removed.

On some desktop platforms (including Windows and Unix), the application name (from QGuiApplication::applicationDisplayName) is added at the end of the window title, if set. This is done by the QPA plugin, so it is shown to the user, but isn't part of the windowTitle string.

See also
windowIcon, windowModified, windowFilePath

Definition at line 151 of file qwidget.h.

Referenced by QToolBar::changeEvent(), QMdiSubWindow::event(), QMdiSubWindow::eventFilter(), QMessageBox::keyPressEvent(), QMdiSubWindowPrivate::removeBaseWidget(), QToolBarAreaLayout::saveState(), QPrintDialogPrivate::setTabs(), QMdiSubWindow::setWidget(), and setWindowTitle().

◆ x

QWidget::x
read

the x coordinate of the widget relative to its parent including any window frame

See the \l{Window Geometry} documentation for an overview of geometry issues with windows.

By default, this property has a value of 0.

See also
frameGeometry, y, pos

Definition at line 109 of file qwidget.h.

Referenced by QCalendarWidgetPrivate::_q_yearClicked(), QDialog::adjustPosition(), QWidgetPrivate::clipRegion(), QQuadPath::controlPointRect(), Viewer::createImage(), QStatusBarPrivate::messageRect(), move(), QColumnViewGrip::moveGrip(), QPagePreview::paintEvent(), QMenuPrivate::popup(), repaint(), resize(), QtPrivate::QColorPicker::resizeEvent(), QtPrivate::QColorPicker::setCol(), QDockWidget::setFloating(), showSystemMenu(), and QFocusFramePrivate::updateSize().

◆ y

QWidget::y
read

the y coordinate of the widget relative to its parent and including any window frame

See the \l{Window Geometry} documentation for an overview of geometry issues with windows.

By default, this property has a value of 0.

See also
frameGeometry, x, pos

Definition at line 110 of file qwidget.h.

Referenced by QCalendarWidgetPrivate::_q_yearClicked(), QDialog::adjustPosition(), QQuadPath::controlPointRect(), Viewer::createImage(), move(), QPagePreview::paintEvent(), QtPrivate::QColorLuminancePicker::paintEvent(), Widget::plusEqualOperator(), repaint(), resize(), QtPrivate::QColorPicker::resizeEvent(), QtPrivate::QColorPicker::setCol(), QDockWidget::setFloating(), QCheckBox::setTristate(), and QFocusFramePrivate::updateSize().


The documentation for this class was generated from the following files: