PySide6.QtWidgets.QWidget¶
- class QWidget¶
The
QWidget
class is the base class of all user interface objects. More…Inherited by:
QWizardPage
,QToolBar
,QTabWidget
,QTabBar
,QStatusBar
,QSplitterHandle
,QSplashScreen
,QSizeGrip
,QRubberBand
,QRhiWidget
,QProgressBar
,QMenuBar
,QMenu
,QMdiSubWindow
,QMainWindow
,QLineEdit
,QKeySequenceEdit
,QGroupBox
,QFrame
,QToolBox
,QStackedWidget
,QSplitter
,QLabel
,QLCDNumber
,QAbstractScrollArea
,QTextEdit
,QTextBrowser
,QScrollArea
,QPlainTextEdit
,QMdiArea
,QGraphicsView
,QAbstractItemView
,QTreeView
,QTreeWidget
,QHelpContentWidget
,QTableView
,QTableWidget
,QListView
,QUndoView
,QListWidget
,QHelpIndexWidget
,QHeaderView
,QColumnView
,QPdfView
,QFocusFrame
,QDockWidget
,QDialogButtonBox
,QDialog
,QWizard
,QProgressDialog
,QMessageBox
,QInputDialog
,QFontDialog
,QErrorMessage
,QColorDialog
,QPrintPreviewDialog
,QPageSetupDialog
,QAbstractPrintDialog
,QPrintDialog
,QComboBox
,QFontComboBox
,QCalendarWidget
,QAbstractSpinBox
,QSpinBox
,QDoubleSpinBox
,QDateTimeEdit
,QTimeEdit
,QDateEdit
,QAbstractSlider
,QSlider
,QScrollBar
,QDial
,QAbstractButton
,QToolButton
,QRadioButton
,QPushButton
,QCommandLinkButton
,QCheckBox
,QSvgWidget
,QQuickWidget
,QPrintPreviewWidget
,QPdfPageSelector
,QOpenGLWidget
,QVideoWidget
,QHelpSearchResultWidget
,QHelpSearchQueryWidget
,QHelpFilterSettingsWidget
,QDesignerWidgetBoxInterface
,QDesignerPropertyEditorInterface
,QDesignerObjectInspectorInterface
,QDesignerFormWindowInterface
,QDesignerActionEditorInterface
,QFileDialog
,QWebEngineView
,QChartView
Synopsis¶
Properties¶
acceptDropsᅟ
- Whether drop events are enabled for this widgetaccessibleDescriptionᅟ
- The widget’s description as seen by assistive technologiesaccessibleNameᅟ
- The widget’s name as seen by assistive technologiesautoFillBackgroundᅟ
- Whether the widget background is filled automaticallybaseSizeᅟ
- The base size of the widgetchildrenRectᅟ
- The bounding rectangle of the widget’s childrenchildrenRegionᅟ
- The combined region occupied by the widget’s childrencontextMenuPolicyᅟ
- How the widget shows a context menucursorᅟ
- The cursor shape for this widgetenabledᅟ
- Whether the widget is enabledfocusᅟ
- Whether this widget (or its focus proxy) has the keyboard input focusfocusPolicyᅟ
- The way the widget accepts keyboard focusfontᅟ
- The font currently set for the widgetframeGeometryᅟ
- Geometry of the widget relative to its parent including any window frameframeSizeᅟ
- The size of the widget including any window framefullScreenᅟ
- Whether the widget is shown in full screen modegeometryᅟ
- The geometry of the widget relative to its parent and excluding the window frameheightᅟ
- The height of the widget excluding any window frameinputMethodHintsᅟ
- What input method specific hints the widget hasisActiveWindowᅟ
- Whether this widget’s window is the active windowlayoutDirectionᅟ
- The layout direction for this widgetlocaleᅟ
- The widget’s localemaximizedᅟ
- Whether this widget is maximizedmaximumHeightᅟ
- The widget’s maximum height in pixelsmaximumSizeᅟ
- The widget’s maximum size in pixelsmaximumWidthᅟ
- The widget’s maximum width in pixelsminimizedᅟ
- Whether this widget is minimized (iconified)minimumHeightᅟ
- The widget’s minimum height in pixelsminimumSizeᅟ
- The widget’s minimum sizeminimumSizeHintᅟ
- The recommended minimum size for the widgetminimumWidthᅟ
- The widget’s minimum width in pixelsmodalᅟ
- Whether the widget is a modal widgetmouseTrackingᅟ
- Whether mouse tracking is enabled for the widgetnormalGeometryᅟ
- The geometry of the widget as it will appear when shown as a normal (not maximized or full screen) top-level widgetpaletteᅟ
- The widget’s paletteposᅟ
- The position of the widget within its parent widgetrectᅟ
- The internal geometry of the widget excluding any window framesizeᅟ
- The size of the widget excluding any window framesizeHintᅟ
- The recommended size for the widgetsizeIncrementᅟ
- The size increment of the widgetsizePolicyᅟ
- The default layout behavior of the widgetstatusTipᅟ
- The widget’s status tipstyleSheetᅟ
- The widget’s style sheettabletTrackingᅟ
- Whether tablet tracking is enabled for the widgettoolTipᅟ
- The widget’s tooltiptoolTipDurationᅟ
- The widget’s tooltip durationupdatesEnabledᅟ
- Whether updates are enabledvisibleᅟ
- Whether the widget is visiblewhatsThisᅟ
- The widget’s What’s This help textwidthᅟ
- The width of the widget excluding any window framewindowFilePathᅟ
- The file path associated with a widgetwindowIconᅟ
- The widget’s iconwindowIconTextᅟ
- The text to be displayed on the icon of a minimized windowwindowModalityᅟ
- Which windows are blocked by the modal widgetwindowModifiedᅟ
- Whether the document shown in the window has unsaved changeswindowOpacityᅟ
- Level of opacity for the windowwindowTitleᅟ
- The window title (caption)xᅟ
- The x coordinate of the widget relative to its parent including any window frameyᅟ
- The y coordinate of the widget relative to its parent and including any window frame
Methods¶
def
__init__()
def
acceptDrops()
def
accessibleName()
def
actions()
def
activateWindow()
def
addAction()
def
addActions()
def
adjustSize()
def
backgroundRole()
def
backingStore()
def
baseSize()
def
childAt()
def
childrenRect()
def
childrenRegion()
def
clearFocus()
def
clearMask()
def
contentsRect()
def
create()
def
createWinId()
def
cursor()
def
destroy()
def
effectiveWinId()
def
ensurePolished()
def
focusNextChild()
def
focusPolicy()
def
focusProxy()
def
focusWidget()
def
font()
def
fontInfo()
def
fontMetrics()
def
foregroundRole()
def
frameGeometry()
def
frameSize()
def
geometry()
def
grab()
def
grabGesture()
def
grabKeyboard()
def
grabMouse()
def
grabShortcut()
def
graphicsEffect()
def
hasFocus()
def
insertAction()
def
insertActions()
def
internalWinId()
def
isActiveWindow()
def
isAncestorOf()
def
isEnabled()
def
isEnabledTo()
def
isFullScreen()
def
isHidden()
def
isLeftToRight()
def
isMaximized()
def
isMinimized()
def
isModal()
def
isRightToLeft()
def
isTopLevel()
def
isVisible()
def
isVisibleTo()
def
isWindow()
def
layout()
def
locale()
def
mapFrom()
def
mapFromGlobal()
def
mapFromParent()
def
mapTo()
def
mapToGlobal()
def
mapToParent()
def
mask()
def
maximumHeight()
def
maximumSize()
def
maximumWidth()
def
minimumHeight()
def
minimumSize()
def
minimumWidth()
def
move()
def
normalGeometry()
def
palette()
def
parentWidget()
def
pos()
def
rect()
def
releaseMouse()
def
removeAction()
def
render()
def
repaint()
def
resize()
def
saveGeometry()
def
screen()
def
scroll()
def
setAcceptDrops()
def
setAttribute()
def
setBaseSize()
def
setCursor()
def
setFixedHeight()
def
setFixedSize()
def
setFixedWidth()
def
setFocus()
def
setFocusPolicy()
def
setFocusProxy()
def
setFont()
def
setGeometry()
def
setLayout()
def
setLocale()
def
setMask()
def
setMaximumSize()
def
setMinimumSize()
def
setPalette()
def
setParent()
def
setScreen()
def
setSizePolicy()
def
setStatusTip()
def
setStyle()
def
setToolTip()
def
setWhatsThis()
def
setWindowFlag()
def
setWindowFlags()
def
setWindowIcon()
def
setWindowRole()
def
setWindowState()
def
size()
def
sizeIncrement()
def
sizePolicy()
def
stackUnder()
def
statusTip()
def
style()
def
styleSheet()
def
testAttribute()
def
toolTip()
def
topLevelWidget()
def
underMouse()
def
ungrabGesture()
def
unsetCursor()
def
unsetLocale()
def
update()
def
updateGeometry()
def
updatesEnabled()
def
visibleRegion()
def
whatsThis()
def
winId()
def
window()
def
windowFilePath()
def
windowFlags()
def
windowHandle()
def
windowIcon()
def
windowIconText()
def
windowModality()
def
windowOpacity()
def
windowRole()
def
windowState()
def
windowTitle()
def
windowType()
def
x()
def
y()
Virtual methods¶
def
actionEvent()
def
changeEvent()
def
closeEvent()
def
dragEnterEvent()
def
dragLeaveEvent()
def
dragMoveEvent()
def
dropEvent()
def
enterEvent()
def
focusInEvent()
def
focusOutEvent()
def
heightForWidth()
def
hideEvent()
def
keyPressEvent()
def
leaveEvent()
def
mouseMoveEvent()
def
moveEvent()
def
nativeEvent()
def
paintEvent()
def
resizeEvent()
def
setVisible()
def
showEvent()
def
sizeHint()
def
tabletEvent()
def
wheelEvent()
Slots¶
def
close()
def
hide()
def
lower()
def
raise_()
def
repaint()
def
setDisabled()
def
setEnabled()
def
setFocus()
def
setHidden()
def
setStyleSheet()
def
setWindowTitle()
def
show()
def
showFullScreen()
def
showMaximized()
def
showMinimized()
def
showNormal()
def
update()
Signals¶
Static functions¶
def
find()
def
mouseGrabber()
def
setTabOrder()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
The widget is the atom of the user interface: it receives mouse, keyboard and other events from the window system, and paints a representation of itself on the screen. Every widget is rectangular, and they are sorted in a Z-order. A widget is clipped by its parent and by the widgets in front of it.
A widget that is not embedded in a parent widget is called a window. Usually, windows have a frame and a title bar, although it is also possible to create windows without such decoration using suitable window flags. In Qt,
QMainWindow
and the various subclasses ofQDialog
are the most common window types.Every widget’s constructor accepts one or two standard arguments:
QWidget *parent = nullptr
is the parent of the new widget. If it isNone
(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.
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 asQLabel
,QPushButton
,QListWidget
, andQTabWidget
.Top-Level and Child Widgets¶
A widget without a parent widget is always an independent window (top-level widget). For these widgets,
setWindowTitle()
andsetWindowIcon()
set the title bar and icon, respectively.Non-window widgets are child widgets, displayed within their parent widgets. Most widgets in Qt are mainly useful as child widgets. For example, it is possible to display a button as a top-level window, but most people prefer to put their buttons inside other widgets, such as
QDialog
.The diagram above shows a
QGroupBox
widget being used to hold various child widgets in a layout provided byQGridLayout
. TheQLabel
child widgets have been outlined to indicate their full sizes.If you want to use a
QWidget
to hold child widgets, you will usually want to add a layout to the parentQWidget
. See Layout Management for more information.Composite Widgets¶
When a widget is used as a container to group a number of child widgets, it is known as a composite widget. These can be created by constructing a widget with the required visual properties - a
QFrame
, for example - and adding child widgets to it, usually managed by a layout.Composite widgets can also be created by subclassing a standard widget, such as
QWidget
orQFrame
, and adding the necessary layout and child widgets in the constructor of the subclass. Many of the examples provided with Qt use this approach, and it is also covered in the Qt Widgets Tutorial .Custom Widgets and Painting¶
Since
QWidget
is a subclass of QPaintDevice, subclasses can be used to display custom content that is composed using a series of painting operations with an instance of the QPainter class. This approach contrasts with the canvas-style approach used by the Graphics View Framework where items are added to a scene by the application and are rendered by the framework itself.Each widget performs all painting operations from within its
paintEvent()
function. This is called whenever the widget needs to be redrawn, either because of some external change or when requested by the application.The Analog Clock example shows how a simple widget can handle paint events.
Size Hints and Size Policies¶
When implementing a new widget, it is almost always useful to reimplement
sizeHint()
to provide a reasonable default size for the widget and to set the correct size policy withsetSizePolicy()
.By default, composite widgets that do not provide a size hint will be sized according to the space requirements of their child widgets.
The size policy lets you supply good default behavior for the layout management system, so that other widgets can contain and manage yours easily. The default size policy indicates that the size hint represents the preferred size of the widget, and this is often good enough for many widgets.
Note
The size of top-level widgets are constrained to 2/3 of the desktop’s height and width. You can
resize()
the widget manually if these bounds are inadequate.Events¶
Widgets respond to events that are typically caused by user actions. Qt delivers events to widgets by calling specific event handler functions with instances of QEvent subclasses containing information about each event.
If your widget only contains child widgets, you probably don’t need to implement any event handlers. If you want to detect a mouse click in a child widget, call the child’s
underMouse()
function inside the widget’smousePressEvent()
.The Scribble example implements a wider set of events to handle mouse movement, button presses, and window resizing.
You will need to supply the behavior and content for your own widgets, but here is a brief overview of the events that are relevant to
QWidget
, starting with the most common ones:paintEvent()
is called whenever the widget needs to be repainted. Every widget displaying custom content must implement it. Painting using a QPainter can only take place in apaintEvent()
or a function called by apaintEvent()
.resizeEvent()
is called when the widget has been resized.mousePressEvent()
is called when a mouse button is pressed while the mouse cursor is inside the widget, or when the widget has grabbed the mouse usinggrabMouse()
. Pressing the mouse without releasing it is effectively the same as callinggrabMouse()
.mouseReleaseEvent()
is called when a mouse button is released. A widget receives mouse release events when it has received the corresponding mouse press event. This means that if the user presses the mouse inside your widget, then drags the mouse somewhere else before releasing the mouse button, your widget receives the release event. There is one exception: if a popup menu appears while the mouse button is held down, this popup immediately steals the mouse events.mouseDoubleClickEvent()
is called when the user double-clicks in the widget. If the user double-clicks, the widget receives a mouse press event, a mouse release event, (a mouse click event,) a second mouse press, this event and finally a second mouse release event. (Some mouse move events may also be received if the mouse is not held steady during this operation.) It is not possible to distinguish a click from a double-click until the second click arrives. (This is one reason why most GUI books recommend that double-clicks be an extension of single-clicks, rather than trigger a different action.)
Widgets that accept keyboard input need to reimplement a few more event handlers:
keyPressEvent()
is called whenever a key is pressed, and again when a key has been held down long enough for it to auto-repeat. The Tab and Shift+Tab keys are only passed to the widget if they are not used by the focus-change mechanisms. To force those keys to be processed by your widget, you must reimplementevent()
.focusInEvent()
is called when the widget gains keyboard focus (assuming you have calledsetFocusPolicy()
). Well-behaved widgets indicate that they own the keyboard focus in a clear but discreet way.focusOutEvent()
is called when the widget loses keyboard focus.
You may be required to also reimplement some of the less common event handlers:
mouseMoveEvent()
is called whenever the mouse moves while a mouse button is held down. This can be useful during drag and drop operations. If you callsetMouseTracking
(true), you get mouse move events even when no buttons are held down. (See also the Drag and Drop guide.)keyReleaseEvent()
is called whenever a key is released and while it is held down (if the key is auto-repeating). In that case, the widget will receive a pair of key release and key press event for every repeat. The Tab and Shift+Tab keys are only passed to the widget if they are not used by the focus-change mechanisms. To force those keys to be processed by your widget, you must reimplementevent()
.wheelEvent()
is called whenever the user turns the mouse wheel while the widget has the focus.enterEvent()
is called when the mouse enters the widget’s screen space. (This excludes screen space owned by any of the widget’s children.)leaveEvent()
is called when the mouse leaves the widget’s screen space. If the mouse enters a child widget, it will not cause aleaveEvent()
.moveEvent()
is called when the widget has been moved relative to its parent.closeEvent()
is called when the user closes the widget (or whenclose()
is called).
There are also some rather obscure events described in the documentation for QEvent::Type. To handle these events, you need to reimplement
event()
directly.The default implementation of
event()
handles Tab and Shift+Tab (to move the keyboard focus), and passes on most of the other events to one of the more specialized handlers above.Events and the mechanism used to deliver them are covered in The Event System.
Groups of Functions and Properties¶
Widget Style Sheets¶
In addition to the standard widget styles for each platform, widgets can also be styled according to rules specified in a style sheet . This feature enables you to customize the appearance of specific widgets to provide visual cues to users about their purpose. For example, a button could be styled in a particular way to indicate that it performs a destructive action.
The use of widget style sheets is described in more detail in the Qt Style Sheets document.
Transparency and Double Buffering¶
QWidget
automatically double-buffers its painting, so there is no need to write double-buffering code inpaintEvent()
to avoid flicker.The contents of parent widgets are propagated by default to each of their children as long as Qt::WA_PaintOnScreen is not set. Custom widgets can be written to take advantage of this feature by updating irregular regions (to create non-rectangular child widgets), or painting with colors that have less than full alpha component. The following diagram shows how attributes and properties of a custom widget can be fine-tuned to achieve different effects.
In the above diagram, a semi-transparent rectangular child widget with an area removed is constructed and added to a parent widget (a
QLabel
showing a pixmap). Then, different properties and widget attributes are set to achieve different effects:The left widget has no additional properties or widget attributes set. This default state suits most custom widgets that have transparency, are irregularly-shaped, or do not paint over their entire area with an opaque brush.
The center widget has the
autoFillBackground
property set. This property is used with custom widgets that rely on the widget to supply a default background, and do not paint over their entire area with an opaque brush.The right widget has the Qt::WA_OpaquePaintEvent widget attribute set. This indicates that the widget will paint over its entire area with opaque colors. The widget’s area will initially be uninitialized, represented in the diagram with a red diagonal grid pattern that shines through the overpainted area.
To rapidly update custom widgets with simple background colors, such as real-time plotting or graphing widgets, it is better to define a suitable background color (using
setBackgroundRole()
with the QPalette::Window role), set theautoFillBackground
property, and only implement the necessary drawing functionality in the widget’spaintEvent()
.To rapidly update custom widgets that constantly paint over their entire areas with opaque content, for example, video streaming widgets, it is better to set the widget’s Qt::WA_OpaquePaintEvent, avoiding any unnecessary overhead associated with repainting the widget’s background.
If a widget has both the Qt::WA_OpaquePaintEvent widget attribute and the
autoFillBackground
property set, the Qt::WA_OpaquePaintEvent attribute takes precedence. Depending on your requirements, you should choose either one of them.The contents of parent widgets are also propagated to standard Qt widgets. This can lead to some unexpected results if the parent widget is decorated in a non-standard way, as shown in the diagram below.
The scope for customizing the painting behavior of standard Qt widgets, without resorting to subclassing, is slightly less than that possible for custom widgets. Usually, the desired appearance of a standard widget can be achieved by setting its
autoFillBackground
property.Creating Translucent Windows¶
You can create windows with translucent regions on window systems that support compositing.
To enable this feature in a top-level widget, set its Qt::WA_TranslucentBackground attribute with
setAttribute()
and ensure that its background is painted with non-opaque colors in the regions you want to be partially transparent.Platform notes:
X11: This feature relies on the use of an X server that supports ARGB visuals and a compositing window manager.
Windows: The widget needs to have the Qt::FramelessWindowHint window flag set for the translucency to work.
macOS: The widget needs to have the Qt::FramelessWindowHint window flag set for the translucency to work.
Native Widgets vs Alien Widgets¶
Alien widgets are widgets unknown to the windowing system. They do not have a native window handle associated with them. This feature significantly speeds up widget painting, resizing, and removes flicker.
Should you require the old behavior with native windows, choose one of the following options:
Use the
QT_USE_NATIVE_WINDOWS=1
in your environment.Set the Qt::AA_NativeWindows attribute on your application. All widgets will be native widgets.
Set the Qt::WA_NativeWindow attribute on widgets: The widget itself and all its ancestors will become native (unless Qt::WA_DontCreateNativeAncestors is set).
Call
winId
to enforce a native window (this implies 3).Set the Qt::WA_PaintOnScreen attribute to enforce a native window (this implies 3).
See also
- class RenderFlag¶
(inherits
enum.Flag
) This enum describes how to render the widget when callingrender()
.Constant
Description
QWidget.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.QWidget.DrawChildren
If you enable this option, the widget’s children are rendered recursively into the target. By default, this option is enabled.
QWidget.IgnoreMask
If you enable this option, the widget’s
mask()
is ignored when rendering into the target. By default, this option is disabled.
Note
Properties can be used directly when
from __feature__ import true_property
is used or via accessor functions otherwise.- property acceptDropsᅟ: bool¶
This property holds whether drop events are enabled for this widget.
Setting this property to true announces to the system that this widget may be able to accept drop events.
If the widget is the desktop (
windowType()
== Qt::Desktop), this may fail if another application is using the desktop; you can call acceptDrops() to test if this occurs.Warning
Do not modify this property in a drag and drop event handler.
By default, this property is
false
.See also
Drag and Drop
- Access functions:
- property accessibleDescriptionᅟ: str¶
This property holds the widget’s description as seen by assistive technologies.
The accessible description of a widget should convey what a widget does. While the
accessibleName
should be a short and concise string (e.g. Save), the description should give more context, such as Saves the current document.This property has to be localized.
By default, this property contains an empty string and Qt falls back to using the tool tip to provide this information.
See also
- Access functions:
- property accessibleNameᅟ: str¶
This property holds the widget’s name as seen by assistive technologies.
This is the primary name by which assistive technology such as screen readers announce this widget. For most widgets setting this property is not required. For example for
QPushButton
the button’s text will be used.It is important to set this property when the widget does not provide any text. For example a button that only contains an icon needs to set this property to work with screen readers. The name should be short and equivalent to the visual information conveyed by the widget.
This property has to be localized.
By default, this property contains an empty string.
See also
- Access functions:
- property autoFillBackgroundᅟ: bool¶
This property holds whether the widget background is filled automatically.
If enabled, this property will cause Qt to fill the background of the widget before invoking the paint event. The color used is defined by the QPalette::Window color role from the widget’s palette.
In addition, Windows are always filled with QPalette::Window, unless the WA_OpaquePaintEvent or WA_NoSystemBackground attributes are set.
This property cannot be turned off (i.e., set to false) if a widget’s parent has a static gradient for its background.
Warning
Use this property with caution in conjunction with Qt Style Sheets . When a widget has a style sheet with a valid background or a border-image, this property is automatically disabled.
By default, this property is
false
.See also
Transparency and Double Buffering
- Access functions:
This property holds the base size of the widget.
The base size is used to calculate a proper widget size if the widget defines
sizeIncrement()
.By default, for a newly-created widget, this property contains a size with zero width and height.
See also
- Access functions:
This property holds the bounding rectangle of the widget’s children.
Hidden children are excluded.
By default, for a widget with no children, this property contains a rectangle with zero width and height located at the origin.
See also
- Access functions:
This property holds the combined region occupied by the widget’s children.
Hidden children are excluded.
By default, for a widget with no children, this property contains an empty region.
See also
- Access functions:
- property contextMenuPolicyᅟ: Qt.ContextMenuPolicy¶
This property holds how the widget shows a context menu.
The default value of this property is Qt::DefaultContextMenu, which means the
contextMenuEvent()
handler is called. Other values are Qt::NoContextMenu, Qt::PreventContextMenu, Qt::ActionsContextMenu, and Qt::CustomContextMenu. With Qt::CustomContextMenu, the signalcustomContextMenuRequested()
is emitted.- Access functions:
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
This property holds the cursor shape for this widget.
The mouse cursor will assume this shape when it’s over this widget. See the list of predefined cursor objects for a range of useful shapes.
An editor widget might use an I-beam cursor:
setCursor(Qt.IBeamCursor)
If no cursor has been set, or after a call to unsetCursor(), the parent’s cursor is used.
By default, this property contains a cursor with the Qt::ArrowCursor shape.
Some underlying window implementations will reset the cursor if it leaves a widget even if the mouse is grabbed. If you want to have a cursor set for all widgets, even when outside the window, consider QGuiApplication::setOverrideCursor().
See also
- Access functions:
- property enabledᅟ: bool¶
This property holds whether the widget is enabled.
In general an enabled widget handles keyboard and mouse events; a disabled widget does not. An exception is made with
QAbstractButton
.Some widgets display themselves differently when they are disabled. For example a button might draw its label grayed out. If your widget needs to know when it becomes enabled or disabled, you can use the
changeEvent()
with type QEvent::EnabledChange.Disabling a widget implicitly disables all its children. Enabling respectively enables all child widgets unless they have been explicitly disabled. It it not possible to explicitly enable a child widget which is not a window while its parent widget remains disabled.
By default, this property is
true
.See also
- Access functions:
- property focusᅟ: bool¶
This property holds whether this widget (or its focus proxy) has the keyboard input focus.
By default, this property is
false
.Note
Obtaining the value of this property for a widget is effectively equivalent to checking whether
focusWidget()
refers to the widget.- Access functions:
- property focusPolicyᅟ: Qt.FocusPolicy¶
This property holds the way the widget accepts keyboard focus.
The policy is Qt::TabFocus if the widget accepts keyboard focus by tabbing, Qt::ClickFocus if the widget accepts focus by clicking, Qt::StrongFocus if it accepts both, and Qt::NoFocus (the default) if it does not accept focus at all.
You must enable keyboard focus for a widget if it processes keyboard events. This is normally done from the widget’s constructor. For instance, the
QLineEdit
constructor calls setFocusPolicy(Qt::StrongFocus).If the widget has a focus proxy, then the focus policy will be propagated to it.
See also
focusInEvent()
focusOutEvent()
keyPressEvent()
keyReleaseEvent()
enabled
- Access functions:
This property holds the font currently set for the widget.
This property describes the widget’s requested font. The font is used by the widget’s style when rendering standard components, and is available as a means to ensure that custom widgets can maintain consistency with the native platform’s look and feel. It’s common that different platforms, or different styles, define different fonts for an application.
When you assign a new font to a widget, the properties from this font are combined with the widget’s default font to form the widget’s final font. You can call
fontInfo()
to get a copy of the widget’s final font. The final font is also used to initialize QPainter’s font.The default depends on the system environment.
QApplication
maintains a system/theme font which serves as a default for all widgets. There may also be special font defaults for certain types of widgets. You can also define default fonts for widgets yourself by passing a custom font and the name of a widget tosetFont()
. 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 (seeisWindow()
) unless the Qt::WA_WindowPropagation attribute is enabled.QWidget
‘s font propagation is similar to its palette propagation.The current style, which is used to render the content of all standard Qt widgets, is free to choose to use the widget font, or in some cases, to ignore it (partially, or completely). In particular, certain styles like GTK style, Mac style, and Windows Vista style, apply special modifications to the widget font to match the platform’s native look and feel. Because of this, assigning properties to a widget’s font is not guaranteed to change the appearance of the widget. Instead, you may choose to apply a styleSheet .
Note
If Qt Style Sheets are used on the same widget as setFont(), style sheets will take precedence if the settings conflict.
See also
This property holds geometry of the widget relative to its parent including any window frame.
See the Window Geometry documentation for an overview of geometry issues with windows.
By default, this property contains a value that depends on the user’s platform and screen geometry.
See also
- Access functions:
This property holds the size of the widget including any window frame.
By default, this property contains a value that depends on the user’s platform and screen geometry.
- Access functions:
- property fullScreenᅟ: bool¶
This property holds whether the widget is shown in full screen mode.
A widget in full screen mode occupies the whole screen area and does not display window decorations, such as a title bar.
By default, this property is
false
.See also
windowState()
minimized
maximized
- Access functions:
This property holds the geometry of the widget relative to its parent and excluding the window frame.
When changing the geometry, the widget, if visible, receives a move event (
moveEvent()
) and/or a resize event (resizeEvent()
) immediately. If the widget is not currently visible, it is guaranteed to receive appropriate events before it is shown.The size component is adjusted if it lies outside the range defined by
minimumSize()
andmaximumSize()
.Warning
Calling setGeometry() inside
resizeEvent()
ormoveEvent()
can lead to infinite recursion.See the Window Geometry documentation for an overview of geometry issues with windows.
By default, this property contains a value that depends on the user’s platform and screen geometry.
- Access functions:
- property heightᅟ: int¶
This property holds the height of the widget excluding any window frame.
See the Window Geometry documentation for an overview of geometry issues with windows.
By default, this property contains a value that depends on the user’s platform and screen geometry.
Access functions:
- property inputMethodHintsᅟ: Combination of Qt.InputMethodHint¶
This property holds What input method specific hints the widget has..
This is only relevant for input widgets. It is used by the input method to retrieve hints as to how the input method should operate. For example, if the Qt::ImhFormattedNumbersOnly flag is set, the input method may change its visual components to reflect that only numbers can be entered.
Warning
Some widgets require certain flags to work as intended. To set a flag, do
w->setInputMethodHints(w->inputMethodHints()|f)
instead ofw->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.
See also
- Access functions:
- property isActiveWindowᅟ: bool¶
This property holds whether this widget’s window is the active window.
The active window is the window that contains the widget that has keyboard focus (The window may still have focus if it has no widgets or none of its widgets accepts keyboard focus).
When popup windows are visible, this property is
true
for both the active window and for the popup.By default, this property is
false
.See also
- Access functions:
- property layoutDirectionᅟ: Qt.LayoutDirection¶
This property holds 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
layoutDirection
- Access functions:
This property holds the widget’s locale.
As long as no special locale has been set, this is either the parent’s locale or (if this widget is a top level widget), the default locale.
If the widget displays dates or numbers, these should be formatted using the widget’s locale.
See also
setDefault()
- Access functions:
- property maximizedᅟ: bool¶
This property holds whether this widget is maximized.
This property is only relevant for windows.
Note
Due to limitations on some window systems, this does not always report the expected results (e.g., if the user on X11 maximizes the window via the window manager, Qt has no way of distinguishing this from any other resize). This is expected to improve as window manager protocols evolve.
By default, this property is
false
.See also
windowState()
showMaximized()
visible
show()
hide()
showNormal()
minimized
- Access functions:
- property maximumHeightᅟ: int¶
This property holds the widget’s maximum height in pixels.
This property corresponds to the height held by the
maximumSize
property.By default, this property contains a value of 16777215.
Note
The definition of the
QWIDGETSIZE_MAX
macro limits the maximum size of widgets.See also
- Access functions:
This property holds the widget’s maximum size in pixels.
The widget cannot be resized to a larger size than the maximum widget size.
By default, this property contains a size in which both width and height have values of 16777215.
Note
The definition of the
QWIDGETSIZE_MAX
macro limits the maximum size of widgets.- Access functions:
- property maximumWidthᅟ: int¶
This property holds the widget’s maximum width in pixels.
This property corresponds to the width held by the
maximumSize
property.By default, this property contains a value of 16777215.
Note
The definition of the
QWIDGETSIZE_MAX
macro limits the maximum size of widgets.See also
- Access functions:
- property minimizedᅟ: bool¶
This property holds 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
- Access functions:
- property minimumHeightᅟ: int¶
This property holds the widget’s minimum height in pixels.
This property corresponds to the height held by the
minimumSize
property.By default, this property has a value of 0.
See also
- Access functions:
This property holds the widget’s minimum size.
The widget cannot be resized to a smaller size than the minimum widget size. The widget’s size is forced to the minimum size if the current size is smaller.
The minimum size set by this function will override the minimum size defined by
QLayout
. To unset the minimum size, use a value ofQSize(0, 0)
.By default, this property contains a size with zero width and height.
- Access functions:
This property holds the recommended minimum size for the widget.
If the value of this property is an invalid size, no minimum size is recommended.
The default implementation of minimumSizeHint() returns an invalid size if there is no layout for this widget, and returns the layout’s minimum size otherwise. Most built-in widgets reimplement minimumSizeHint().
QLayout
will never resize a widget to a size smaller than the minimum size hint unlessminimumSize()
is set or the size policy is set to QSizePolicy::Ignore. IfminimumSize()
is set, the minimum size hint will be ignored.See also
- Access functions:
- property minimumWidthᅟ: int¶
This property holds the widget’s minimum width in pixels.
This property corresponds to the width held by the
minimumSize
property.By default, this property has a value of 0.
See also
- Access functions:
- property modalᅟ: bool¶
This property holds whether the widget is a modal widget.
This property only makes sense for windows. A modal widget prevents widgets in all other windows from getting any input.
By default, this property is
false
.See also
- Access functions:
- property mouseTrackingᅟ: bool¶
This property holds whether mouse tracking is enabled for the widget.
If mouse tracking is disabled (the default), the widget only receives mouse move events when at least one mouse button is pressed while the mouse is being moved.
If mouse tracking is enabled, the widget receives mouse move events even if no buttons are pressed.
See also
- Access functions:
This property holds the geometry of the widget as it will appear when shown as a normal (not maximized or full screen) top-level widget.
If the widget is already in this state the normal geometry will reflect the widget’s current
geometry()
.For child widgets this property always holds an empty rectangle.
By default, this property contains an empty rectangle.
See also
- Access functions:
This property holds the widget’s palette.
This property describes the widget’s palette. The palette is used by the widget’s style when rendering standard components, and is available as a means to ensure that custom widgets can maintain consistency with the native platform’s look and feel. It’s common that different platforms, or different styles, have different palettes.
When you assign a new palette to a widget, the color roles from this palette are combined with the widget’s default palette to form the widget’s final palette. The palette entry for the widget’s background role is used to fill the widget’s background (see
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 fromQMenuBar
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 tosetPalette()
. Finally, the style always has the option of polishing the palette as it’s assigned (seepolish()
).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 (seeisWindow()
) 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 styleSheet .
Warning
Do not use this function in conjunction with Qt Style Sheets . When using style sheets, the palette of a widget can be customized using the “color”, “background-color”, “selection-color”, “selection-background-color” and “alternate-background-color”.
See also
- Access functions:
This property holds the position of the widget within its parent widget.
If the widget is a window, the position is that of the widget on the desktop, including its frame.
When changing the position, the widget, if visible, receives a move event (
moveEvent()
) immediately. If the widget is not currently visible, it is guaranteed to receive an event before it is shown.By default, this property contains a position that refers to the origin.
Warning
Calling move() or
setGeometry()
insidemoveEvent()
can lead to infinite recursion.See the 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
This property holds the internal geometry of the widget excluding any window frame.
The rect property equals QRect(0, 0,
width()
,height()
).See the Window Geometry documentation for an overview of geometry issues with windows.
By default, this property contains a value that depends on the user’s platform and screen geometry.
See also
- Access functions:
This property holds the size of the widget excluding any window frame.
If the widget is visible when it is being resized, it receives a resize event (
resizeEvent()
) immediately. If the widget is not currently visible, it is guaranteed to receive an event before it is shown.The size is adjusted if it lies outside the range defined by
minimumSize()
andmaximumSize()
.By default, this property contains a value that depends on the user’s platform and screen geometry.
Warning
Calling resize() or
setGeometry()
insideresizeEvent()
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.This property holds the recommended size for the widget.
If the value of this property is an invalid size, no size is recommended.
The default implementation of sizeHint() returns an invalid size if there is no layout for this widget, and returns the layout’s preferred size otherwise.
- Access functions:
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
This property holds the size increment of the widget.
When the user resizes the window, the size will move in steps of sizeIncrement().
width()
pixels horizontally and sizeIncrement.height()
pixels vertically, withbaseSize()
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
- Access functions:
- property sizePolicyᅟ: QSizePolicy¶
This property holds the default layout behavior of the widget.
If there is a
QLayout
that manages this widget’s children, the size policy specified by that layout is used. If there is no suchQLayout
, 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 asQLineEdit
,QSpinBox
or an editableQComboBox
) and other horizontally orientated widgets (such asQProgressBar
).QToolButton
‘s are normally square, so they allow growth in both directions. Widgets that support different directions (such asQSlider
,QScrollBar
or QHeader) specify stretching in the respective direction only. Widgets that can provide scroll bars (usually subclasses ofQScrollArea
) tend to specify that they can use additional space, and that they can make do with less thansizeHint()
.See also
- Access functions:
- property statusTipᅟ: str¶
This property holds the widget’s status tip.
By default, this property contains an empty string.
- Access functions:
- property styleSheetᅟ: str¶
This property holds the widget’s style sheet.
The style sheet contains a textual description of customizations to the widget’s style, as described in the Qt Style Sheets document.
Since Qt 4.5, Qt style sheets fully supports macOS.
Warning
Qt style sheets are currently not supported for custom
QStyle
subclasses. We plan to address this in some future release.See also
- Access functions:
- property tabletTrackingᅟ: bool¶
This property holds whether tablet tracking is enabled for the widget.
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
- Access functions:
- property toolTipᅟ: str¶
This property holds the widget’s tooltip.
Note that by default tooltips are only shown for widgets that are children of the active window. You can change this behavior by setting the attribute Qt::WA_AlwaysShowToolTips on the window, not on the widget with the tooltip.
If you want to control a tooltip’s behavior, you can intercept the
event()
function and catch the QEvent::ToolTip event (e.g., if you want to customize the area for which the tooltip should be shown).By default, this property contains an empty string.
- Access functions:
- property toolTipDurationᅟ: int¶
This property holds the widget’s tooltip duration.
Specifies how long time the tooltip will be displayed, in milliseconds. If the value is -1 (default) the duration is calculated depending on the length of the tooltip.
See also
- Access functions:
- property updatesEnabledᅟ: bool¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
This property holds whether updates are enabled.
An updates enabled widget receives paint events and has a system background; a disabled widget does not. This also implies that calling
update()
andrepaint()
has no effect if updates are disabled.By default, this property is
true
.setUpdatesEnabled() is normally used to disable updates for a short period of time, for instance to avoid screen flicker during large changes. In Qt, widgets normally do not generate screen flicker, but on X11 the server might erase regions on the screen when widgets get hidden before they can be replaced by other widgets. Disabling updates solves this.
Example:
setUpdatesEnabled(False) bigVisualChanges() setUpdatesEnabled(True)
Disabling a widget implicitly disables all its children. Enabling a widget enables all child widgets except top-level widgets or those that have been explicitly disabled. Re-enabling updates implicitly calls
update()
on the widget.See also
- Access functions:
- property visibleᅟ: bool¶
This property holds whether the widget is visible.
Calling setVisible(true) or
show()
sets the widget to visible status if all its parent widgets up to the window are visible. If an ancestor is not visible, the widget won’t become visible until all its ancestors are shown. If its size or position has changed, Qt guarantees that a widget gets move and resize events just before it is shown. If the widget has not been resized yet, Qt will adjust the widget’s size to a useful default usingadjustSize()
.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 theevent()
function.- Access functions:
- property whatsThisᅟ: str¶
This property holds the widget’s What’s This help text..
By default, this property contains an empty string.
See also
- Access functions:
- property widthᅟ: int¶
This property holds the width of the widget excluding any window frame.
See the Window Geometry documentation for an overview of geometry issues with windows.
Note
Do not use this function to find the width of a screen on a multi-screen desktop. See QScreen for details.
By default, this property contains a value that depends on the user’s platform and screen geometry.
Access functions:
- property windowFilePathᅟ: str¶
This property holds the file path associated with a widget.
This property only makes sense for windows. It associates a file path with a window. If you set the file path, but have not set the window title, Qt sets the window title to 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 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
- Access functions:
This property holds the widget’s icon.
This property only makes sense for windows. If no icon has been set, windowIcon() returns the application icon (QApplication::windowIcon()).
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
- Access functions:
- property windowIconTextᅟ: str¶
This property holds 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.
This property is deprecated.
See also
- Access functions:
- property windowModalityᅟ: Qt.WindowModality¶
This property holds which windows are blocked by the modal widget.
This property only makes sense for windows. A modal widget prevents widgets in other windows from getting input. The value of this property controls which windows are blocked when the widget is visible. Changing this property while the window is visible has no effect; you must
hide()
the widget first, thenshow()
it again.By default, this property is Qt::NonModal.
See also
isWindow()
modal
QDialog
- Access functions:
- property windowModifiedᅟ: bool¶
This property holds whether the document shown in the window has unsaved changes.
A modified window is a window whose content has changed but has not been saved to disk. This flag will have different effects varied by the platform. On 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
- Access functions:
- property windowOpacityᅟ: float¶
This property holds The level of opacity for the window..
The valid range of opacity is from 1.0 (completely opaque) to 0.0 (completely transparent).
By default the value of this property is 1.0.
This feature is available on Embedded Linux, 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
- Access functions:
- property windowTitleᅟ: str¶
This property holds the window title (caption).
This property only makes sense for top-level widgets, such as windows and dialogs. If no caption has been set, the title is based of the
windowFilePath
. If neither of these is set, then the title is an empty string.If you use the
windowModified
mechanism, the window title must contain a “[*]” placeholder, which indicates where the ‘*’ should appear. Normally, it should appear right after the file name (e.g., “document1.txt[*] - Text Editor”). If thewindowModified
property isfalse
(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
- Access functions:
- property xᅟ: int¶
This property holds the x coordinate of the widget relative to its parent including any window frame.
See the Window Geometry documentation for an overview of geometry issues with windows.
By default, this property has a value of 0.
See also
- Access functions:
- property yᅟ: int¶
This property holds the y coordinate of the widget relative to its parent and including any window frame.
See the Window Geometry documentation for an overview of geometry issues with windows.
By default, this property has a value of 0.
See also
- Access functions:
- __init__([parent=None[, f=Qt.WindowFlags()]])¶
- Parameters:
parent –
QWidget
f – Combination of
WindowType
Constructs a widget which is a child of
parent
, with widget flags set tof
.If
parent
isNone
, the new widget becomes a window. Ifparent
is another widget, this widget becomes a child window insideparent
. The new widget is deleted when itsparent
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 beNone
). To customize the frame, use a value composed from the bitwise OR of any of the window flags.If you add a child widget to an already visible widget you must explicitly show the child to make it visible.
Note that the X11 version of Qt may not be able to deliver all combinations of style flags on all systems. This is because on X11, Qt can only ask the window manager, and the window manager can override the application’s settings. On Windows, Qt can set whatever flags you want.
See also
- acceptDrops()¶
- Return type:
bool
See also
Getter of property
acceptDropsᅟ
.- accessibleDescription()¶
- Return type:
str
See also
Getter of property
accessibleDescriptionᅟ
.- accessibleName()¶
- Return type:
str
See also
Getter of property
accessibleNameᅟ
.- actionEvent(event)¶
- Parameters:
event –
QActionEvent
This event handler is called with the given
event
whenever the widget’s actions are changed.Returns the (possibly empty) list of this widget’s actions.
- 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
Appends the action
action
to this widget’s list of actions.All QWidgets have a list of QActions. However, they can be represented graphically in many different ways. The default use of the QAction list (as returned by
actions()
) is to create a contextQMenu
.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 thisQWidget
.See also
- addAction(text)
- Parameters:
text – str
- Return type:
- addAction(text, callable)
- Parameters:
text – str
callable – object
- Return type:
- addAction(text, shortcut)
- Parameters:
text – str
shortcut –
QKeySequence
- Return type:
- addAction(icon, text, callable)
- addAction(text, shortcut, callable)
- Parameters:
text – str
shortcut –
QKeySequence
callable – object
- Return type:
- addAction(icon, text, shortcut)
- Parameters:
icon –
QIcon
text – str
shortcut –
QKeySequence
- Return type:
- addAction(icon, text, shortcut, callable)
- Parameters:
icon –
QIcon
text – str
shortcut –
QKeySequence
callable – object
- Return type:
- addAction(text, receiver, member[, type=Qt.AutoConnection])
- Parameters:
text – str
receiver –
QObject
member – str
type –
ConnectionType
- Return type:
- addAction(icon, text, receiver, member[, type=Qt.AutoConnection])
- Parameters:
icon –
QIcon
text – str
receiver –
QObject
member – str
type –
ConnectionType
- Return type:
- addAction(text, shortcut, receiver, member[, type=Qt.AutoConnection])
- Parameters:
text – str
shortcut –
QKeySequence
receiver –
QObject
member – str
type –
ConnectionType
- Return type:
- addAction(icon, text, shortcut, receiver, member[, type=Qt.AutoConnection])
- Parameters:
icon –
QIcon
text – str
shortcut –
QKeySequence
receiver –
QObject
member – str
type –
ConnectionType
- Return type:
- addActions(actions)¶
- Parameters:
actions – .list of QAction
Appends the actions
actions
to this widget’s list of actions.See also
- 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 isexpanding
, 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
- autoFillBackground()¶
- Return type:
bool
See also
Getter of property
autoFillBackgroundᅟ
.Returns the background role of the widget.
The background role defines the brush from the widget’s
palette
that is used to render the background.If no explicit background role is set, the widget inherits its parent widget’s background role.
See also
- backingStore()¶
- Return type:
Returns the QBackingStore this widget will be drawn into.
- baseSize()¶
- Return type:
See also
Getter of property
baseSizeᅟ
.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.
This is an overloaded function.
Returns the visible child widget at point
p
in the widget’s own coordinate system.This is an overloaded function.
Returns the visible child widget at point
p
in the widget’s own coordinate system.- childAt(x, y)
- Parameters:
x – int
y – int
- Return type:
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 returnsNone
.Getter of property
childrenRectᅟ
.Getter of property
childrenRegionᅟ
.- clearFocus()¶
Takes keyboard input focus from the widget.
If the widget has active focus, a
focus out event
is sent to this widget to tell it that it has lost the focus.This widget must enable focus setting to get the keyboard input focus; that is, it must call
setFocusPolicy()
.- clearMask()¶
Removes any mask set by
setMask()
.See also
- close()¶
- Return type:
bool
Closes this widget. Returns
true
if the widget was closed; otherwise returnsfalse
.First it sends the widget a QCloseEvent. The widget is
hidden
if it accepts the close event. If it ignores the event, nothing happens. The default implementation ofcloseEvent()
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 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.
- closeEvent(event)¶
- Parameters:
event –
QCloseEvent
This event handler is called with the given
event
when Qt receives a window close request for a top-level widget from the window system.By default, the event is accepted and the widget is closed. You can reimplement this function to change the way the widget responds to window close requests. For example, you can prevent the window from closing by calling ignore() on all events.
Main window applications typically use reimplementations of this function to check whether the user’s work has been saved and ask for permission before closing.
See also
event()
hide()
close()
QCloseEvent
The contentsMargins function returns the widget’s contents margins.
See also
Returns the area inside the widget’s margins.
See also
- contextMenuEvent(event)¶
- Parameters:
event –
QContextMenuEvent
This event handler, for event
event
, can be reimplemented in a subclass to receive widget context menu events.The handler is called when the widget’s
contextMenuPolicy
is Qt::DefaultContextMenu.The default implementation ignores the context event. See the QContextMenuEvent documentation for more details.
See also
event()
customContextMenuRequested()
- contextMenuPolicy()¶
- Return type:
See also
Getter of property
contextMenuPolicyᅟ
.- create([arg__1=0[, initializeWindow=true[, destroyOldWindow=true]]])¶
- Parameters:
arg__1 –
WId
initializeWindow – bool
destroyOldWindow – bool
Creates a new widget window.
The parameters
window
,initializeWindow
, anddestroyOldWindow
are ignored in Qt 5. Please use QWindow::fromWinId() to create a QWindow wrapping a foreign window and pass it tocreateWindowContainer()
instead.See also
- createWinId()¶
- static createWindowContainer(window[, parent=None[, flags=Qt.WindowFlags()]])¶
- Parameters:
window –
QWindow
parent –
QWidget
flags – Combination of
WindowType
- Return type:
Creates a
QWidget
that makes it possible to embedwindow
into aQWidget
-based application.The window container is created as a child of
parent
and with window flagsflags
.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
orQMdiArea
, it will create anative 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:
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.
Rendering Integration; The window container does not interoperate with
QGraphicsProxyWidget
,render()
or similar functionality.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 callingwindowHandle()
), no container will be created. Instead, this function will return the widget itself, after being reparented to parent. Since no container will be created,flags
will be ignored. In other words, ifwindow
belongs to a widget, consider just reparenting that widget toparent
instead of using this function.
- cursor()¶
- Return type:
See also
Getter of property
cursorᅟ
.This signal is emitted when the widget’s
contextMenuPolicy
is Qt::CustomContextMenu, and the user has requested a context menu on the widget. The positionpos
is the position of the context menu event that the widget receives. Normally this is in widget coordinates. The exception to this rule isQAbstractScrollArea
and its subclasses that map the context menu event to coordinates of theviewport()
.See also
- destroy([destroyWindow=true[, destroySubWindows=true]])¶
- Parameters:
destroyWindow – bool
destroySubWindows – bool
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 thedestroyWindow
parameter. To have more control over destruction of subwidgets, destroy subwidgets selectively first.This function is usually called from the
QWidget
destructor.- dragEnterEvent(event)¶
- Parameters:
event –
QDragEnterEvent
This event handler is called when a drag is in progress and the mouse enters this widget. The event is passed in the
event
parameter.If the event is ignored, the widget won’t receive any
drag move events
.See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.
See also
QDragQDragEnterEvent
- dragLeaveEvent(event)¶
- Parameters:
event –
QDragLeaveEvent
This event handler is called when a drag is in progress and the mouse leaves this widget. The event is passed in the
event
parameter.See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.
See also
QDragQDragLeaveEvent
- dragMoveEvent(event)¶
- Parameters:
event –
QDragMoveEvent
This event handler is called if a drag is in progress, and when any of the following conditions occur: the cursor enters this widget, the cursor moves within this widget, or a modifier key is pressed on the keyboard while this widget has the focus. The event is passed in the
event
parameter.See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.
See also
QDragQDragMoveEvent
- dropEvent(event)¶
- Parameters:
event –
QDropEvent
This event handler is called when the drag is dropped on this widget. The event is passed in the
event
parameter.See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.
See also
QDragQDropEvent
- effectiveWinId()¶
- Return type:
WId
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
- ensurePolished()¶
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’ssizeHint()
reimplementation. Note that this function is called from the default implementation ofsizeHint()
.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()
- enterEvent(event)¶
- Parameters:
event –
QEnterEvent
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()
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,None
is returned.- focusInEvent(event)¶
- Parameters:
event –
QFocusEvent
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
parameterA widget normally must
setFocusPolicy()
to something other than Qt::NoFocus to receive focus events. (Note that the application programmer can callsetFocus()
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
- focusNextChild()¶
- Return type:
bool
Finds a new widget to give the keyboard focus to, as appropriate for Tab, and returns
true
if it can find a new widget, or false if it can’t.See also
- focusNextPrevChild(next)¶
- Parameters:
next – bool
- Return type:
bool
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, ifnext
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
- focusOutEvent(event)¶
- Parameters:
event –
QFocusEvent
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 callsetFocus()
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
- focusPolicy()¶
- Return type:
See also
Getter of property
focusPolicyᅟ
.- focusPreviousChild()¶
- Return type:
bool
Finds a new widget to give the keyboard focus to, as appropriate for Shift+Tab, and returns
true
if it can find a new widget, or false if it can’t.See also
Returns the focus proxy, or
None
if there is no focus proxy.See also
Returns the last child of this widget that
setFocus
had been called on. For top level widgets this is the widget that will get focus in case this window gets activatedThis is not the same as
focusWidget()
, which returns the focus widget in the currently active window.Getter of property
fontᅟ
.Returns the font info for the widget’s current font. Equivalent to
QFontInfo(widget->font())
.See also
- fontMetrics()¶
- Return type:
Returns the font metrics for the widget’s current font. Equivalent to
QFontMetrics(widget->font())
.See also
Returns the foreground role.
The foreground role defines the color from the widget’s
palette
that is used to draw the foreground.If no explicit foreground role is set, the function returns a role that contrasts with the background role.
See also
Getter of property
frameGeometryᅟ
.Getter of property
frameSizeᅟ
.- geometry()¶
- Return type:
See also
Getter of property
geometryᅟ
.- grab([rectangle=QRect(QPoint(0, 0), QSize(-1, -1))])¶
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.
- grabGesture(type[, flags=Qt.GestureFlags()])¶
- Parameters:
type –
GestureType
flags – Combination of
GestureFlag
Subscribes the widget to a given
gesture
with specificflags
.See also
- 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. UsegrabMouse()
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 afterreleaseKeyboard()
is called.If a different widget is currently grabbing keyboard input, that widget’s grab is released first.
- 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. UsegrabKeyboard()
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()
returnsfalse
for a widget, that widget cannot call grabMouse().Note
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.
- grabMouse(arg__1)
- Parameters:
arg__1 –
QCursor
This function overloads
grabMouse()
.Grabs the mouse input and changes the cursor shape.
The cursor will assume shape
cursor
(for as long as the mouse focus is grabbed) and this widget will be the only one to receive mouse events untilreleaseMouse()
is called().Warning
Grabbing the mouse might lock the terminal.
Note
See the note in
grabMouse()
.- grabShortcut(key[, context=Qt.WindowShortcut])¶
- Parameters:
key –
QKeySequence
context –
ShortcutContext
- Return type:
int
Adds a shortcut to Qt’s shortcut system that watches for the given
key
sequence in the givencontext
. If thecontext
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 thekey
sequence occurs a QEvent::Shortcut event is sent to all the widgets to which it applies in a non-deterministic order, but with the ``ambiguous’’ flag set to true.Warning
You should not normally need to use this function; instead create QActions with the shortcut key sequences you require (if you also want equivalent menu options and toolbar buttons), or create QShortcuts if you just need key sequences. Both QAction and QShortcut handle all the event filtering for you, and provide signals which are triggered when the user triggers the key sequence, so are much easier to use than this low-level function.
See also
- graphicsEffect()¶
- Return type:
The graphicsEffect function returns a pointer to the widget’s graphics effect.
If the widget has no graphics effect,
None
is returned.See also
- graphicsProxyWidget()¶
- Return type:
Returns the proxy widget for the corresponding embedded widget in a graphics view; otherwise returns
None
.See also
- hasFocus()¶
- Return type:
bool
Getter of property
focusᅟ
.- hasHeightForWidth()¶
- Return type:
bool
Returns
true
if the widget’s preferred height depends on its width; otherwise returnsfalse
.- hasMouseTracking()¶
- Return type:
bool
Getter of property
mouseTrackingᅟ
.- hasTabletTracking()¶
- Return type:
bool
Getter of property
tabletTrackingᅟ
.- heightForWidth(arg__1)¶
- Parameters:
arg__1 – int
- Return type:
int
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.
- hide()¶
Hides the widget. This function is equivalent to
setVisible
(false).Note
If you are working with
QDialog
or its subclasses and you invoke theshow()
function after this function, the dialog will be displayed in its original position.- hideEvent(event)¶
- Parameters:
event –
QHideEvent
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
- inputMethodEvent(event)¶
- Parameters:
event –
QInputMethodEvent
This event handler, for event
event
, can be reimplemented in a subclass to receive Input Method composition events. This handler is called when the state of the input method changes.Note that when creating custom text editing widgets, the Qt::WA_InputMethodEnabled window attribute must be set explicitly (using the
setAttribute()
function) in order to receive input method events.The default implementation calls event->ignore(), which rejects the Input Method event. See the QInputMethodEvent documentation for more details.
See also
event()
QInputMethodEvent
- inputMethodHints()¶
- Return type:
Combination of
InputMethodHint
See also
Getter of property
inputMethodHintsᅟ
.- inputMethodQuery(arg__1)¶
- Parameters:
arg__1 –
InputMethodQuery
- Return type:
object
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
Inserts the action
action
to this widget’s list of actions, before the actionbefore
. It appends the action ifbefore
isNone
orbefore
is not a valid action for this widget.A
QWidget
should only have one of each action.Inserts the actions
actions
to this widget’s list of actions, before the actionbefore
. It appends the action ifbefore
isNone
orbefore
is not a valid action for this widget.A
QWidget
can have at most one of each action.- internalWinId()¶
- Return type:
WId
- isActiveWindow()¶
- Return type:
bool
Getter of property
isActiveWindowᅟ
.Returns
true
if this widget is a parent, (or grandparent and so on to any level), of the givenchild
, and both widgets are within the same window; otherwise returnsfalse
.- isEnabled()¶
- Return type:
bool
Getter of property
enabledᅟ
.Returns
true
if this widget would become enabled ifancestor
is enabled; otherwise returnsfalse
.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
- isFullScreen()¶
- Return type:
bool
Getter of property
fullScreenᅟ
.- isHidden()¶
- Return type:
bool
Returns
true
if the widget is hidden, otherwise returnsfalse
.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:
they were created as independent windows,
they were created as children of visible widgets,
hide()
orsetVisible
(false) was called.
- isLeftToRight()¶
- Return type:
bool
- isMaximized()¶
- Return type:
bool
Getter of property
maximizedᅟ
.- isMinimized()¶
- Return type:
bool
Getter of property
minimizedᅟ
.- isModal()¶
- Return type:
bool
Getter of property
modalᅟ
.- isRightToLeft()¶
- Return type:
bool
- isTopLevel()¶
- Return type:
bool
Note
This function is deprecated.
Use
isWindow()
instead.- isVisible()¶
- Return type:
bool
Getter of property
visibleᅟ
.Returns
true
if this widget would become visible ifancestor
is shown; otherwise returnsfalse
.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
- isWindow()¶
- Return type:
bool
Returns
true
if the widget is an independent window, otherwise returnsfalse
.A window is a widget that isn’t visually the child of any other widget and that usually has a frame and a
window title
.A window can have a
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
andQMainWindow
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
- isWindowModified()¶
- Return type:
bool
Getter of property
windowModifiedᅟ
.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
This event handler, for event
event
, can be reimplemented in a subclass to receive key release events for the widget.A widget must
accept focus
initially andhave 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()
setFocusPolicy()
focusInEvent()
focusOutEvent()
event()
QKeyEvent
Returns the widget that is currently grabbing the keyboard input.
If no widget in this application is currently grabbing the keyboard,
None
is returned.See also
Returns the layout manager that is installed on this widget, or
None
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
- layoutDirection()¶
- Return type:
See also
Getter of property
layoutDirectionᅟ
.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()
- locale()¶
- Return type:
See also
Getter of property
localeᅟ
.- lower()¶
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()
This is an overloaded function.
Translates the widget coordinate
pos
from the coordinate system ofparent
to this widget’s coordinate system. Theparent
must not beNone
and must be a parent of the calling widget.This is an overloaded function.
Translates the global screen coordinate
pos
to widget coordinates.See also
This is an overloaded function.
Translates the parent widget coordinate
pos
to widget coordinates.Same as
mapFromGlobal()
if the widget has no parent.This is an overloaded function.
Translates the widget coordinate
pos
to the coordinate system ofparent
. Theparent
must not beNone
and must be a parent of the calling widget.See also
This is an overloaded function.
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
This is an overloaded function.
Translates the widget coordinate
pos
to a coordinate in the parent widget.Same as
mapToGlobal()
if the widget has no parent.See also
Returns the mask currently set on a widget. If no mask is set the return value will be an empty region.
See also
- maximumHeight()¶
- Return type:
int
See also
Getter of property
maximumHeightᅟ
.- maximumSize()¶
- Return type:
See also
Getter of property
maximumSizeᅟ
.- maximumWidth()¶
- Return type:
int
See also
Getter of property
maximumWidthᅟ
.- minimumHeight()¶
- Return type:
int
See also
Getter of property
minimumHeightᅟ
.- minimumSize()¶
- Return type:
See also
Getter of property
minimumSizeᅟ
.Getter of property
minimumSizeHintᅟ
.- minimumWidth()¶
- Return type:
int
See also
Getter of property
minimumWidthᅟ
.- mouseDoubleClickEvent(event)¶
- Parameters:
event –
QMouseEvent
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
Returns the widget that is currently grabbing the mouse input.
If no widget in this application is currently grabbing the mouse,
None
is returned.See also
- mouseMoveEvent(event)¶
- Parameters:
event –
QMouseEvent
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
showText()
instead ofsetToolTip()
in your implementation of mouseMoveEvent().See also
setMouseTracking()
mousePressEvent()
mouseReleaseEvent()
mouseDoubleClickEvent()
event()
Scribble Example- mousePressEvent(event)¶
- Parameters:
event –
QMouseEvent
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()
Scribble Example- mouseReleaseEvent(event)¶
- Parameters:
event –
QMouseEvent
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()
Scribble ExampleSetter of property
posᅟ
.- move(x, y)
- Parameters:
x – int
y – int
This is an overloaded function.
This corresponds to move(QPoint(
x
,y
)).- moveEvent(event)¶
- Parameters:
event –
QMoveEvent
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
- nativeEvent(eventType, message)¶
- Parameters:
eventType –
QByteArray
message –
void
- Return type:
PyObject
This special event handler can be reimplemented in a subclass to receive native platform events identified by
eventType
which are passed in themessage
parameter.In your reimplementation of this function, if you want to stop the event being handled by Qt, return true and set
result
. Theresult
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.
Note
This function superseedes the event filter functions x11Event(), winEvent() and macEvent() of Qt 4.
Platform
Event Type Identifier
Message Type
Result Type
Windows
“windows_generic_MSG”
MSG *
LRESULT
macOS
“NSEvent”
NSEvent *
XCB
“xcb_generic_event_t”
xcb_generic_event_t *
See also
Returns the native parent for this widget, i.e. the next ancestor widget that has a system identifier, or
None
if it does not have any native parent.See also
Returns the next widget in this widget’s focus chain.
See also
Getter of property
normalGeometryᅟ
.- overrideWindowFlags(type)¶
- Parameters:
type – Combination of
WindowType
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
- overrideWindowState(state)¶
- Parameters:
state – Combination of
WindowState
- paintEvent(event)¶
- Parameters:
event –
QPaintEvent
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:
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
andQTableView
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()). Therepaint()
function does not permit this optimization, so we suggest usingupdate()
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()
andsetPalette()
.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()
orrepaint()
inside a paintEvent(). For example, callingupdate()
orrepaint()
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,
paintEngine()
will never be called; the backingstore will be used instead.- palette()¶
- Return type:
See also
Getter of property
paletteᅟ
.Returns the parent of this widget, or
None
if it does not have any parent widget.Getter of property
posᅟ
.The previousInFocusChain function returns the previous widget in this widget’s focus chain.
See also
- raise_()¶
Getter of property
rectᅟ
.- releaseKeyboard()¶
Releases the keyboard grab.
See also
- releaseMouse()¶
Releases the mouse grab.
See also
- releaseShortcut(id)¶
- Parameters:
id – int
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
Removes the action
action
from this widget’s list of actions.See also
- render(target[, targetOffset=QPoint()[, sourceRegion=QRegion()[, renderFlags=QWidget.RenderFlags(QWidget.RenderFlag.DrawWindowBackground | QWidget.RenderFlag.DrawChildren)]]])¶
- Parameters:
target –
QPaintDevice
targetOffset –
QPoint
sourceRegion –
QRegion
renderFlags – Combination of
RenderFlag
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Renders the
sourceRegion
of this widget into thetarget
usingrenderFlags
to determine how to render. Rendering starts attargetOffset
in thetarget
. For example:pixmap = QPixmap(widget.size()) widget.render(pixmap)
If
sourceRegion
is a null region, this function will userect()
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 = QPainter(self) ... painter.end() myWidget.render(self)
Note
To obtain the contents of a QOpenGLWidget, use QOpenGLWidget::grabFramebuffer() instead.
- render(painter, targetOffset[, sourceRegion=QRegion()[, renderFlags=QWidget.RenderFlags(QWidget.RenderFlag.DrawWindowBackground | QWidget.RenderFlag.DrawChildren)]])
- Parameters:
painter –
QPainter
targetOffset –
QPoint
sourceRegion –
QRegion
renderFlags – Combination of
RenderFlag
This is an overloaded function.
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 thepainter
.See also
- repaint()¶
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. Theupdate()
function never causes recursion.See also
- repaint(arg__1)
- Parameters:
arg__1 –
QRect
This is an overloaded function.
This version repaints a rectangle
rect
inside the widget.- repaint(arg__1)
- Parameters:
arg__1 –
QRegion
This is an overloaded function.
This version repaints a region
rgn
inside the widget.- repaint(x, y, w, h)
- Parameters:
x – int
y – int
w – int
h – int
This is an overloaded function.
This version repaints a rectangle (
x
,y
,w
,h
) inside the widget.If
w
is negative, it is replaced withwidth() - x
, and ifh
is negative, it is replaced widthheight() - y
.Setter of property
sizeᅟ
.- resize(w, h)
- Parameters:
w – int
h – int
This is an overloaded function.
This corresponds to resize(QSize(
w
,h
)).- resizeEvent(event)¶
- Parameters:
event –
QResizeEvent
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()
paintEvent()
Scribble Example- restoreGeometry(geometry)¶
- Parameters:
geometry –
QByteArray
- Return type:
bool
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Restores the geometry and state of top-level widgets stored in the byte array
geometry
. Returnstrue
on success; otherwise returnsfalse
.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:
settings = QSettings("MyCompany", "MyApp") myWidget.restoreGeometry(settings.value("myWidget/geometry").toByteArray())
See the Window Geometry documentation for an overview of geometry issues with windows.
Use
restoreState()
to restore the geometry and the state of toolbars and dock widgets.See also
- saveGeometry()¶
- Return type:
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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:
def closeEvent(self, event): settings = QSettings("MyCompany", "MyApp") settings.setValue("geometry", saveGeometry()) QWidget.closeEvent(event)
See the Window Geometry documentation for an overview of geometry issues with windows.
Use
saveState()
to save the geometry and the state of toolbars and dock widgets.See also
Returns the screen the widget is on.
See also
- scroll(dx, dy)¶
- Parameters:
dx – int
dy – int
Scrolls the widget including its children
dx
pixels to the right anddy
downward. Bothdx
anddy
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
autoFillBackground
property, or usesetAttribute()
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
- scroll(dx, dy, arg__3)
- Parameters:
dx – int
dy – int
arg__3 –
QRect
This is an overloaded function.
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
- setAcceptDrops(on)¶
- Parameters:
on – bool
See also
Setter of property
acceptDropsᅟ
.- setAccessibleDescription(description)¶
- Parameters:
description – str
See also
Setter of property
accessibleDescriptionᅟ
.- setAccessibleName(name)¶
- Parameters:
name – str
See also
Setter of property
accessibleNameᅟ
.- setAttribute(arg__1[, on=true])¶
- Parameters:
arg__1 –
WidgetAttribute
on – bool
Sets the attribute
attribute
on this widget ifon
is true; otherwise clears the attribute.See also
- setAutoFillBackground(enabled)¶
- Parameters:
enabled – bool
See also
Setter of property
autoFillBackgroundᅟ
.Sets the background role of the widget to
role
.The background role defines the brush from the widget’s
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
Setter of property
baseSizeᅟ
.- setBaseSize(basew, baseh)
- Parameters:
basew – int
baseh – int
This is an overloaded function.
This corresponds to
setBaseSize
(QSize(basew
,baseh
)). Sets the widgets base size to widthbasew
and heightbaseh
.This is an overloaded function.
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
- setContentsMargins(left, top, right, bottom)
- Parameters:
left – int
top – int
right – int
bottom – int
Sets the margins around the contents of the widget to have the sizes
left
,top
,right
, andbottom
. 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
- setContextMenuPolicy(policy)¶
- Parameters:
policy –
ContextMenuPolicy
See also
Setter of property
contextMenuPolicyᅟ
.Setter of property
cursorᅟ
.- setDisabled(arg__1)¶
- Parameters:
arg__1 – bool
Disables widget input events if
disable
is true; otherwise enables input events.See the
enabled
documentation for more information.See also
- setEnabled(arg__1)¶
- Parameters:
arg__1 – bool
See also
Setter of property
enabledᅟ
.- setFixedHeight(h)¶
- Parameters:
h – int
Sets both the minimum and maximum heights of the widget to
h
without changing the widths. Provided for convenience.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
setSizeConstraint
(SetFixedSize
);See also
- setFixedSize(w, h)
- Parameters:
w – int
h – int
This is an overloaded function.
Sets the width of the widget to
w
and the height toh
.- setFixedWidth(w)¶
- Parameters:
w – int
Sets both the minimum and maximum width of the widget to
w
without changing the heights. Provided for convenience.- setFocus()¶
This is an overloaded function.
Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the
active window
.- setFocus(reason)
- Parameters:
reason –
FocusReason
Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the
active window
. Thereason
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 (seegrabKeyboard()
).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 fromfocusOutEvent()
orfocusInEvent()
, you may get an infinite recursion.See also
hasFocus()
clearFocus()
focusInEvent()
focusOutEvent()
setFocusPolicy()
focusWidget()
focusWidget()
grabKeyboard()
grabMouse()
Keyboard Focus in WidgetsRequestSoftwareInputPanel
- setFocusPolicy(policy)¶
- Parameters:
policy –
FocusPolicy
See also
Setter of property
focusPolicyᅟ
.Sets the widget’s focus proxy to widget
w
. Ifw
isNone
, 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()
andhasFocus()
operate on the focus proxy. If “this widget” is the focus widget, then setFocusProxy() moves focus to the new focus proxy.See also
Setter of property
fontᅟ
.Sets the foreground role of the widget to
role
.The foreground role defines the color from the widget’s
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
Setter of property
geometryᅟ
.- setGeometry(x, y, w, h)
- Parameters:
x – int
y – int
w – int
h – int
This is an overloaded function.
This corresponds to
setGeometry
(QRect(x
,y
,w
,h
)).- setGraphicsEffect(effect)¶
- Parameters:
effect –
QGraphicsEffect
The setGraphicsEffect function is for setting the widget’s graphics effect.
Sets
effect
as the widget’s effect. If there already is an effect installed on this widget,QWidget
will delete the existing effect before installing the neweffect
.If
effect
is the installed effect on a different widget, setGraphicsEffect() will remove the effect from the widget and install it on this widget.QWidget
takes ownership ofeffect
.Note
This function will apply the effect on itself and all its children.
Note
Graphics effects are not supported for OpenGL-based widgets, such as QGLWidget, QOpenGLWidget and QQuickWidget.
See also
- setHidden(hidden)¶
- Parameters:
hidden – bool
Convenience function, equivalent to
setVisible
(!``hidden``).See also
- setInputMethodHints(hints)¶
- Parameters:
hints – Combination of
InputMethodHint
See also
Setter of property
inputMethodHintsᅟ
.Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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 bylayout()
) 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:
layout = QVBoxLayout() layout.addWidget(formWidget) setLayout(layout)
An alternative to calling this function is to pass this widget to the layout’s constructor.
The
QWidget
will take ownership oflayout
.See also
- setLayoutDirection(direction)¶
- Parameters:
direction –
LayoutDirection
See also
Setter of property
layoutDirectionᅟ
.Setter of property
localeᅟ
.Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Causes only the pixels of the widget for which
bitmap
has a corresponding 1 bit to be visible. If the region includes pixels outside therect()
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:
topLevelLabel = QLabel() pixmap = QPixmap(":/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
- setMask(arg__1)
- Parameters:
arg__1 –
QRegion
This is an overloaded function.
Causes only the parts of the widget which overlap
region
to be visible. If the region includes pixels outside therect()
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 Translucent Background example.
See also
- setMaximumHeight(maxh)¶
- Parameters:
maxh – int
See also
Setter of property
maximumHeightᅟ
.Setter of property
maximumSizeᅟ
.- setMaximumSize(maxw, maxh)
- Parameters:
maxw – int
maxh – int
This is an overloaded function.
This function corresponds to
setMaximumSize
(QSize(maxw
,maxh
)). Sets the maximum width tomaxw
and the maximum height tomaxh
.- setMaximumWidth(maxw)¶
- Parameters:
maxw – int
See also
Setter of property
maximumWidthᅟ
.- setMinimumHeight(minh)¶
- Parameters:
minh – int
See also
Setter of property
minimumHeightᅟ
.Setter of property
minimumSizeᅟ
.- setMinimumSize(minw, minh)
- Parameters:
minw – int
minh – int
This is an overloaded function.
This function corresponds to
setMinimumSize
(QSize(minw, minh)). Sets the minimum width tominw
and the minimum height tominh
.- setMinimumWidth(minw)¶
- Parameters:
minw – int
See also
Setter of property
minimumWidthᅟ
.- setMouseTracking(enable)¶
- Parameters:
enable – bool
See also
Setter of property
mouseTrackingᅟ
.Setter of property
paletteᅟ
.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
tab chain
of the new parent widget, in the same internal order as before. If one of the moved widgets had keyboard focus, setParent() callsclearFocus()
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
QStackedWidget
.See also
- setParent(parent, f)
- Parameters:
parent –
QWidget
f – Combination of
WindowType
This is an overloaded function.
This function also takes widget flags,
f
as an argument.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
- setShortcutAutoRepeat(id[, enable=true])¶
- Parameters:
id – int
enable – bool
If
enable
is true, auto repeat of the shortcut with the givenid
is enabled; otherwise it is disabled.See also
- setShortcutEnabled(id[, enable=true])¶
- Parameters:
id – int
enable – bool
If
enable
is true, the shortcut with the givenid
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
Setter of property
sizeIncrementᅟ
.- setSizeIncrement(w, h)
- Parameters:
w – int
h – int
This is an overloaded function.
Sets the x (width) size increment to
w
and the y (height) size increment toh
.- setSizePolicy(arg__1)¶
- Parameters:
arg__1 –
QSizePolicy
See also
Setter of property
sizePolicyᅟ
.This is an overloaded function.
Sets the size policy of the widget to
horizontal
andvertical
, with standard stretch and no height-for-width.See also
QSizePolicy()
- setStatusTip(arg__1)¶
- Parameters:
arg__1 – str
See also
Setter of property
statusTipᅟ
.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,
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.
Warning
Qt style sheets are currently not supported for custom
QStyle
subclasses. We plan to address this in some future release.See also
- setStyleSheet(styleSheet)¶
- Parameters:
styleSheet – str
See also
Setter of property
styleSheetᅟ
.Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Puts the
second
widget after thefirst
widget in the focus order.It effectively removes the
second
widget from its focus chain and inserts it after thefirst
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
orsecond
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 insidesecond
.- setTabletTracking(enable)¶
- Parameters:
enable – bool
See also
Setter of property
tabletTrackingᅟ
.Setter of property
toolTipᅟ
.- setToolTipDuration(msec)¶
- Parameters:
msec – int
See also
Setter of property
toolTipDurationᅟ
.- setUpdatesEnabled(enable)¶
- Parameters:
enable – bool
See also
Setter of property
updatesEnabledᅟ
.- setVisible(visible)¶
- Parameters:
visible – bool
See also
Setter of property
visibleᅟ
.- setWhatsThis(arg__1)¶
- Parameters:
arg__1 – str
See also
Setter of property
whatsThisᅟ
.- setWindowFilePath(filePath)¶
- Parameters:
filePath – str
See also
Setter of property
windowFilePathᅟ
.- setWindowFlag(arg__1[, on=true])¶
- Parameters:
arg__1 –
WindowType
on – bool
Sets the window flag
flag
on this widget ifon
is true; otherwise clears the flag.See also
- setWindowFlags(type)¶
- Parameters:
type – Combination of
WindowType
See also
Setter of property
windowIconᅟ
.- setWindowIconText(arg__1)¶
- Parameters:
arg__1 – str
See also
Setter of property
windowIconTextᅟ
.- setWindowModality(windowModality)¶
- Parameters:
windowModality –
WindowModality
See also
Setter of property
windowModalityᅟ
.- setWindowModified(arg__1)¶
- Parameters:
arg__1 – bool
See also
Setter of property
windowModifiedᅟ
.- setWindowOpacity(level)¶
- Parameters:
level – float
See also
- setWindowRole(arg__1)¶
- Parameters:
arg__1 – str
Sets the window’s role to
role
. This only makes sense for windows on X11.See also
- setWindowState(state)¶
- Parameters:
state – Combination of
WindowState
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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()
returnsfalse
), the window state will take effect whenshow()
is called. For visible windows, the change is immediate. For example, to toggle between full-screen and normal mode, use the following code:w.setWindowState(w.windowState() ^ Qt.WindowFullScreen)
To restore and activate a minimized window (while preserving its maximized and/or full-screen state), use the following:
w.setWindowState((w.windowState() ~Qt.WindowMinimized) | Qt.WindowActive)
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
- setWindowTitle(arg__1)¶
- Parameters:
arg__1 – str
See also
Setter of property
windowTitleᅟ
.- show()¶
Shows the widget and its child widgets.
For child windows, this is equivalent to calling
setVisible
(true). Otherwise, it is equivalent to callingshowFullScreen()
,showMaximized()
, orsetVisible
(true), depending on the platform’s default behavior for the window flags.See also
raise()
showEvent()
hide()
setVisible()
showMinimized()
showMaximized()
showNormal()
isVisible()
windowFlags()
- showEvent(event)¶
- Parameters:
event –
QShowEvent
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
- showFullScreen()¶
Shows the widget in full-screen mode.
Calling this function only affects
windows
.To return from full-screen mode, call
showNormal()
orclose()
.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 byclose()
on the full screen window before showing another window.See also
- showMaximized()¶
Shows the widget maximized.
Calling this function only affects
windows
.On X11, this function may not work properly with certain window managers. See the Window Geometry documentation for an explanation.
- showMinimized()¶
Shows the widget minimized, as an icon.
Calling this function only affects
windows
.- showNormal()¶
Restores the widget after it has been maximized or minimized.
Calling this function only affects
windows
.Getter of property
sizeᅟ
.Getter of property
sizeHintᅟ
.- sizeIncrement()¶
- Return type:
See also
Getter of property
sizeIncrementᅟ
.- sizePolicy()¶
- Return type:
See also
Getter of property
sizePolicyᅟ
.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()
- statusTip()¶
- Return type:
str
See also
Getter of property
statusTipᅟ
.- style()¶
- Return type:
See also
- styleSheet()¶
- Return type:
str
See also
Getter of property
styleSheetᅟ
.- tabletEvent(event)¶
- Parameters:
event –
QTabletEvent
This event handler, for event
event
, can be reimplemented in a subclass to receive tablet events for the widget.If you reimplement this handler, it is very important that you ignore() the event if you do not handle it, so that the widget’s parent can interpret it.
The default implementation ignores the event.
If tablet tracking is switched off, tablet move events only occur if 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 switched on, tablet move events occur even while the stylus is hovering in proximity of the tablet, with no buttons pressed.
See also
event()
setTabletTracking()
QTabletEvent
- testAttribute(arg__1)¶
- Parameters:
arg__1 –
WidgetAttribute
- Return type:
bool
Returns
true
if attributeattribute
is set on this widget; otherwise returnsfalse
.See also
- toolTip()¶
- Return type:
str
See also
Getter of property
toolTipᅟ
.- toolTipDuration()¶
- Return type:
int
See also
Getter of property
toolTipDurationᅟ
.Use
window()
instead.- underMouse()¶
- Return type:
bool
Returns
true
if the widget is under the mouse cursor; otherwise returnsfalse
.This value is not updated properly during drag and drop operations.
See also
- ungrabGesture(type)¶
- Parameters:
type –
GestureType
Unsubscribes the widget from a given
gesture
typeSee also
- unsetCursor()¶
Reset function of property
cursorᅟ
.- unsetLayoutDirection()¶
Reset function of property
layoutDirectionᅟ
.- unsetLocale()¶
Reset function of property
localeᅟ
.- update()¶
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- update(arg__1)
- Parameters:
arg__1 –
QRect
This is an overloaded function.
This version updates a rectangle
rect
inside the widget.- update(arg__1)
- Parameters:
arg__1 –
QRegion
This is an overloaded function.
This version repaints a region
rgn
inside the widget.- update(x, y, w, h)
- Parameters:
x – int
y – int
w – int
h – int
This is an overloaded function.
This version updates a rectangle (
x
,y
,w
,h
) inside the widget.- updateGeometry()¶
Notifies the layout system that this widget has changed and may need to change geometry.
Call this function if the
sizeHint()
orsizePolicy()
have changed.For explicitly hidden widgets, updateGeometry() is a no-op. The layout system will be notified as soon as the widget is shown.
- updateMicroFocus([query=Qt.ImQueryAll])¶
- Parameters:
query –
InputMethodQuery
Updates the widget’s micro focus and informs input methods that the state specified by
query
has changed.- updatesEnabled()¶
- Return type:
bool
See also
Getter of property
updatesEnabledᅟ
.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.- whatsThis()¶
- Return type:
str
See also
Getter of property
whatsThisᅟ
.- wheelEvent(event)¶
- Parameters:
event –
QWheelEvent
This event handler, for event
event
, can be reimplemented in a subclass to receive wheel events for the widget.If you reimplement this handler, it is very important that you ignore() the event if you do not handle it, so that the widget’s parent can interpret it.
The default implementation ignores the event.
See also
event()
QWheelEvent
- winId()¶
- Return type:
WId
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
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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:
aWidget.window().setWindowTitle("New Window Title")
See also
- windowFilePath()¶
- Return type:
str
See also
Getter of property
windowFilePathᅟ
.- windowFlags()¶
- Return type:
Combination of
WindowType
See also
If this is a native widget, return the associated QWindow. Otherwise return null.
Native widgets include toplevel widgets, QGLWidget, and child widgets on which
winId()
was called.- windowIcon()¶
- Return type:
See also
Getter of property
windowIconᅟ
.This signal is emitted when the window’s icon has changed, with the new
icon
as an argument.Notification signal of property
windowIconᅟ
.- windowIconText()¶
- Return type:
str
See also
Getter of property
windowIconTextᅟ
.- windowIconTextChanged(iconText)¶
- Parameters:
iconText – str
This signal is emitted when the window’s icon text has changed, with the new
iconText
as an argument.This signal is deprecated.
Notification signal of property
windowIconTextᅟ
.- windowModality()¶
- Return type:
See also
Getter of property
windowModalityᅟ
.- windowOpacity()¶
- Return type:
float
See also
- windowRole()¶
- Return type:
str
Returns the window’s role, or an empty string.
See also
- windowState()¶
- Return type:
Combination of
WindowState
Returns the current window state. The window state is a OR’ed combination of Qt::WindowState: Qt::WindowMinimized, Qt::WindowMaximized, Qt::WindowFullScreen, and Qt::WindowActive.
See also
- windowTitle()¶
- Return type:
str
See also
Getter of property
windowTitleᅟ
.- windowTitleChanged(title)¶
- Parameters:
title – str
This signal is emitted when the window’s title has changed, with the new
title
as an argument.Notification signal of property
windowTitleᅟ
.- windowType()¶
- Return type:
Returns the window type of this widget. This is identical to
windowFlags()
& Qt::WindowType_Mask.See also
- x()¶
- Return type:
int
Getter of property
xᅟ
.- y()¶
- Return type:
int
Getter of property
yᅟ
.