QWidget

Inheritance diagram of QWidget

Inherited by: QRubberBand, QTabWidget, QTabBar, QCalendarWidget, QGLWidget, QAbstractSpinBox, QHelpSearchResultWidget, QHelpSearchQueryWidget, QAbstractSlider, QSlider, QFrame, QAbstractScrollArea, QGraphicsView, QDeclarativeView, QAbstractButton, QCheckBox, QWebInspector, QDesktopWidget, QX11EmbedContainer, QX11EmbedWidget, QWorkspace, QToolButton, QToolBox, QToolBar, QStatusBar, QStackedWidget, QSplitterHandle, QSplitter, QSplashScreen, QSvgWidget, QDoubleSpinBox, QSpinBox, QSizeGrip, QScrollBar, QScrollArea, QRadioButton, QProgressBar, QPrintPreviewWidget, QPlainTextEdit, QTextEdit, QTextBrowser, QMenuBar, QMenu, QMdiSubWindow, QMdiArea, QMainWindow, QLineEdit, QLCDNumber, QLabel, QGroupBox, QFocusFrame, QDockWidget, QDialogButtonBox, QDial, QDateTimeEdit, QDateEdit, QTimeEdit, QPushButton, QCommandLinkButton, QComboBox, QFontComboBox, QAbstractItemView, QHeaderView, QTreeView, QTreeWidget, QHelpContentWidget, QColumnView, QTableView, QTableWidget, QListView, QHelpIndexWidget, QUndoView, QListWidget, Phonon.VolumeSlider, Phonon.VideoPlayer, QWizardPage, Phonon.SeekSlider, Phonon.EffectWidget, QDialog, QFileDialog, QErrorMessage, QColorDialog, QAbstractPrintDialog, QPrintDialog, QAbstractPageSetupDialog, QPageSetupDialog, QWizard, QProgressDialog, QPrintPreviewDialog, QMessageBox, QInputDialog, QFontDialog, QWebView

Synopsis

Functions

Virtual functions

Slots

Signals

Static functions

Detailed Description

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

The widget is the atom of the user interface: it receives mouse, keyboard and other events from the window system, and paints a representation of itself on the screen. Every widget is rectangular, and they are sorted in a Z-order. A widget is clipped by its parent and by the widgets in front of it.

A widget that is not embedded in a parent widget is called a window. Usually, windows have a frame and a title bar, although it is also possible to create windows without such decoration using suitable window flags ). In Qt, PySide.QtGui.QMainWindow and the various subclasses of PySide.QtGui.QDialog are the most common window types.

Every widget’s constructor accepts one or two standard arguments:

PySide.QtGui.QWidget has many member functions, but some of them have little direct functionality; for example, PySide.QtGui.QWidget has a font property, but never uses this itself. There are many subclasses which provide real functionality, such as PySide.QtGui.QLabel , PySide.QtGui.QPushButton , PySide.QtGui.QListWidget , and PySide.QtGui.QTabWidget .

Top-Level and Child Widgets

A widget without a parent widget is always an independent window (top-level widget). For these widgets, PySide.QtGui.QWidget.setWindowTitle() and PySide.QtGui.QWidget.setWindowIcon() set the title bar and icon respectively.

Non-window widgets are child widgets, displayed within their parent widgets. Most widgets in Qt are mainly useful as child widgets. For example, it is possible to display a button as a top-level window, but most people prefer to put their buttons inside other widgets, such as PySide.QtGui.QDialog .

../../_images/parent-child-widgets.png

The diagram above shows a PySide.QtGui.QGroupBox widget being used to hold various child widgets in a layout provided by PySide.QtGui.QGridLayout . The PySide.QtGui.QLabel child widgets have been outlined to indicate their full sizes.

If you want to use a PySide.QtGui.QWidget to hold child widgets you will usually want to add a layout to the parent PySide.QtGui.QWidget . See Layout Management for more information.

Composite Widgets

When a widget is used as a container to group a number of child widgets, it is known as a composite widget. These can be created by constructing a widget with the required visual properties - a PySide.QtGui.QFrame , for example - and adding child widgets to it, usually managed by a layout. The above diagram shows such a composite widget that was created using Qt Designer .

Composite widgets can also be created by subclassing a standard widget, such as PySide.QtGui.QWidget or PySide.QtGui.QFrame , and adding the necessary layout and child widgets in the constructor of the subclass. Many of the examples provided with Qt use this approach, and it is also covered in the Qt Tutorials .

Custom Widgets and Painting

Since PySide.QtGui.QWidget is a subclass of PySide.QtGui.QPaintDevice , subclasses can be used to display custom content that is composed using a series of painting operations with an instance of the PySide.QtGui.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 PySide.QtGui.QWidget.paintEvent() function. This is called whenever the widget needs to be redrawn, either as a result of some external change or when requested by the application.

The Analog Clock example shows how a simple widget can handle paint events.

Size Hints and Size Policies

When implementing a new widget, it is almost always useful to reimplement PySide.QtGui.QWidget.sizeHint() to provide a reasonable default size for the widget and to set the correct size policy with PySide.QtGui.QWidget.setSizePolicy() .

By default, composite widgets which do not provide a size hint will be sized according to the space requirements of their child widgets.

The size policy lets you supply good default behavior for the layout management system, so that other widgets can contain and manage yours easily. The default size policy indicates that the size hint represents the preferred size of the widget, and this is often good enough for many widgets.

Note

The size of top-level widgets are constrained to 2/3 of the desktop’s height and width. You can PySide.QtGui.QWidget.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 PySide.QtCore.QEvent subclasses containing information about each event.

If your widget only contains child widgets, you probably do not need to implement any event handlers. If you want to detect a mouse click in a child widget call the child’s PySide.QtGui.QWidget.underMouse() function inside the widget’s PySide.QtGui.QWidget.mousePressEvent() .

The Scribble example implements a wider set of events to handle mouse movement, button presses, and window resizing.

You will need to supply the behavior and content for your own widgets, but here is a brief overview of the events that are relevant to PySide.QtGui.QWidget , starting with the most common ones:

  • PySide.QtGui.QWidget.paintEvent() is called whenever the widget needs to be repainted. Every widget displaying custom content must implement it. Painting using a PySide.QtGui.QPainter can only take place in a PySide.QtGui.QWidget.paintEvent() or a function called by a PySide.QtGui.QWidget.paintEvent() .
  • PySide.QtGui.QWidget.resizeEvent() is called when the widget has been resized.
  • PySide.QtGui.QWidget.mousePressEvent() is called when a mouse button is pressed while the mouse cursor is inside the widget, or when the widget has grabbed the mouse using PySide.QtGui.QWidget.grabMouse() . Pressing the mouse without releasing it is effectively the same as calling PySide.QtGui.QWidget.grabMouse() .
  • PySide.QtGui.QWidget.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.
  • PySide.QtGui.QWidget.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 and finally this event instead of a second mouse press 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:

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

There are also some rather obscure events described in the documentation for QEvent.Type . To handle these events, you need to reimplement PySide.QtGui.QWidget.event() directly.

The default implementation of PySide.QtGui.QWidget.event() handles Tab and Shift+Tab (to move the keyboard focus), and passes on most of the other events to one of the more specialized handlers above.

Events and the mechanism used to deliver them are covered in The Event System .

Groups of Functions and Properties

Context Functions and Properties
Window functions PySide.QtGui.QWidget.show() , PySide.QtGui.QWidget.hide() , raise() , PySide.QtGui.QWidget.lower() , PySide.QtGui.QWidget.close() .
Top-level windows windowModified() , PySide.QtGui.QWidget.windowTitle() , PySide.QtGui.QWidget.windowIcon() , PySide.QtGui.QWidget.windowIconText() , PySide.QtGui.QWidget.isActiveWindow() , PySide.QtGui.QWidget.activateWindow() , minimized() , PySide.QtGui.QWidget.showMinimized() , maximized() , PySide.QtGui.QWidget.showMaximized() , fullScreen() , PySide.QtGui.QWidget.showFullScreen() , PySide.QtGui.QWidget.showNormal() .
Window contents PySide.QtGui.QWidget.update() , PySide.QtGui.QWidget.repaint() , PySide.QtGui.QWidget.scroll() .
Geometry PySide.QtGui.QWidget.pos() , PySide.QtGui.QWidget.x() , PySide.QtGui.QWidget.y() , PySide.QtGui.QWidget.rect() , PySide.QtGui.QWidget.size() , PySide.QtGui.QWidget.width() , PySide.QtGui.QWidget.height() , PySide.QtGui.QWidget.move() , PySide.QtGui.QWidget.resize() , PySide.QtGui.QWidget.sizePolicy() , PySide.QtGui.QWidget.sizeHint() , PySide.QtGui.QWidget.minimumSizeHint() , PySide.QtGui.QWidget.updateGeometry() , PySide.QtGui.QWidget.layout() , PySide.QtGui.QWidget.frameGeometry() , PySide.QtGui.QWidget.geometry() , PySide.QtGui.QWidget.childrenRect() , PySide.QtGui.QWidget.childrenRegion() , PySide.QtGui.QWidget.adjustSize() , PySide.QtGui.QWidget.mapFromGlobal() , PySide.QtGui.QWidget.mapToGlobal() , PySide.QtGui.QWidget.mapFromParent() , PySide.QtGui.QWidget.mapToParent() , PySide.QtGui.QWidget.maximumSize() , PySide.QtGui.QWidget.minimumSize() , PySide.QtGui.QWidget.sizeIncrement() , PySide.QtGui.QWidget.baseSize() , PySide.QtGui.QWidget.setFixedSize()
Mode visible() , PySide.QtGui.QWidget.isVisibleTo() , enabled() , PySide.QtGui.QWidget.isEnabledTo() , modal() , PySide.QtGui.QWidget.isWindow() , mouseTracking() , PySide.QtGui.QWidget.updatesEnabled() , PySide.QtGui.QWidget.visibleRegion() .
Look and feel PySide.QtGui.QWidget.style() , PySide.QtGui.QWidget.setStyle() , PySide.QtGui.QWidget.styleSheet() , PySide.QtGui.QWidget.cursor() , PySide.QtGui.QWidget.font() , PySide.QtGui.QWidget.palette() , PySide.QtGui.QWidget.backgroundRole() , PySide.QtGui.QWidget.setBackgroundRole() , PySide.QtGui.QWidget.fontInfo() , PySide.QtGui.QWidget.fontMetrics() .
Keyboard focus functions focus() , PySide.QtGui.QWidget.focusPolicy() , PySide.QtGui.QWidget.setFocus() , PySide.QtGui.QWidget.clearFocus() , PySide.QtGui.QWidget.setTabOrder() , PySide.QtGui.QWidget.setFocusProxy() , PySide.QtGui.QWidget.focusNextChild() , PySide.QtGui.QWidget.focusPreviousChild() .
Mouse and keyboard grabbing PySide.QtGui.QWidget.grabMouse() , PySide.QtGui.QWidget.releaseMouse() , PySide.QtGui.QWidget.grabKeyboard() , PySide.QtGui.QWidget.releaseKeyboard() , PySide.QtGui.QWidget.mouseGrabber() , PySide.QtGui.QWidget.keyboardGrabber() .
Event handlers PySide.QtGui.QWidget.event() , PySide.QtGui.QWidget.mousePressEvent() , PySide.QtGui.QWidget.mouseReleaseEvent() , PySide.QtGui.QWidget.mouseDoubleClickEvent() , PySide.QtGui.QWidget.mouseMoveEvent() , PySide.QtGui.QWidget.keyPressEvent() , PySide.QtGui.QWidget.keyReleaseEvent() , PySide.QtGui.QWidget.focusInEvent() , PySide.QtGui.QWidget.focusOutEvent() , PySide.QtGui.QWidget.wheelEvent() , PySide.QtGui.QWidget.enterEvent() , PySide.QtGui.QWidget.leaveEvent() , PySide.QtGui.QWidget.paintEvent() , PySide.QtGui.QWidget.moveEvent() , PySide.QtGui.QWidget.resizeEvent() , PySide.QtGui.QWidget.closeEvent() , PySide.QtGui.QWidget.dragEnterEvent() , PySide.QtGui.QWidget.dragMoveEvent() , PySide.QtGui.QWidget.dragLeaveEvent() , PySide.QtGui.QWidget.dropEvent() , PySide.QtCore.QObject.childEvent() , PySide.QtGui.QWidget.showEvent() , PySide.QtGui.QWidget.hideEvent() , PySide.QtCore.QObject.customEvent() . PySide.QtGui.QWidget.changeEvent() ,
System functions PySide.QtGui.QWidget.parentWidget() , PySide.QtGui.QWidget.window() , PySide.QtGui.QWidget.setParent() , PySide.QtGui.QWidget.winId() , find() , PySide.QtGui.QWidget.metric() .
Interactive help PySide.QtGui.QWidget.setToolTip() , PySide.QtGui.QWidget.setWhatsThis()

Widget Style Sheets

In addition to the standard widget styles for each platform, widgets can also be styled according to rules specified in a style sheet . This feature enables you to customize the appearance of specific widgets to provide visual cues to users about their purpose. For example, a button could be styled in a particular way to indicate that it performs a destructive action.

The use of widget style sheets is described in more detail in the Qt Style Sheets document.

Transparency and Double Buffering

Since Qt 4.0, PySide.QtGui.QWidget automatically double-buffers its painting, so there is no need to write double-buffering code in PySide.QtGui.QWidget.paintEvent() to avoid flicker.

Since Qt 4.1, the Qt.WA_ContentsPropagated widget attribute has been deprecated. Instead, the contents of parent widgets are propagated by default to each of their children as long as Qt.WA_PaintOnScreen is not set. Custom widgets can be written to take advantage of this feature by updating irregular regions (to create non-rectangular child widgets), or painting with colors that have less than full alpha component. The following diagram shows how attributes and properties of a custom widget can be fine-tuned to achieve different effects.

../../_images/propagation-custom.png

In the above diagram, a semi-transparent rectangular child widget with an area removed is constructed and added to a parent widget (a PySide.QtGui.QLabel showing a pixmap). Then, different properties and widget attributes are set to achieve different effects:

  • The left widget has no additional properties or widget attributes set. This default state suits most custom widgets using transparency, are irregularly-shaped, or do not paint over their entire area with an opaque brush.
  • The center widget has the PySide.QtGui.QWidget.autoFillBackground() property set. This property is used with custom widgets that rely on the widget to supply a default background, and do not paint over their entire area with an opaque brush.
  • The right widget has the Qt.WA_OpaquePaintEvent widget attribute set. This indicates that the widget will paint over its entire area with opaque colors. The widget’s area will initially be uninitialized, represented in the diagram with a red diagonal grid pattern that shines through the overpainted area. The Qt::WA_OpaquePaintArea attribute is useful for widgets that need to paint their own specialized contents quickly and do not need a default filled background.

To rapidly update custom widgets with simple background colors, such as real-time plotting or graphing widgets, it is better to define a suitable background color (using PySide.QtGui.QWidget.setBackgroundRole() with the QPalette.Window role), set the PySide.QtGui.QWidget.autoFillBackground() property, and only implement the necessary drawing functionality in the widget’s PySide.QtGui.QWidget.paintEvent() .

To rapidly update custom widgets that constantly paint over their entire areas with opaque content, e.g., video streaming widgets, it is better to set the widget’s Qt.WA_OpaquePaintEvent , avoiding any unnecessary overhead associated with repainting the widget’s background.

If a widget has both the Qt.WA_OpaquePaintEvent widget attribute and the PySide.QtGui.QWidget.autoFillBackground() property set, the Qt.WA_OpaquePaintEvent attribute takes precedence. Depending on your requirements, you should choose either one of them.

Since Qt 4.1, the contents of parent widgets are also propagated to standard Qt widgets. This can lead to some unexpected results if the parent widget is decorated in a non-standard way, as shown in the diagram below.

../../_images/propagation-standard.png

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 PySide.QtGui.QWidget.autoFillBackground() property.

Creating Translucent Windows

Since Qt 4.5, it has been possible to create windows with translucent regions on window systems that support compositing.

To enable this feature in a top-level widget, set its Qt.WA_TranslucentBackground attribute with PySide.QtGui.QWidget.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.

Native Widgets vs Alien Widgets

Introduced in Qt 4.4, alien widgets are widgets unknown to the windowing system. They do not have a native window handle associated with them. This feature significantly speeds up widget painting, resizing, and removes flicker.

Should you require the old behavior with native windows, you can choose one of the following options:

Softkeys

Since Qt 4.6, Softkeys are usually physical keys on a device that have a corresponding label or other visual representation on the screen that is generally located next to its physical counterpart. They are most often found on mobile phone platforms. In modern touch based user interfaces it is also possible to have softkeys that do not correspond to any physical keys. Softkeys differ from other onscreen labels in that they are contextual.

In Qt, contextual softkeys are added to a widget by calling PySide.QtGui.QWidget.addAction() and passing a QAction with a softkey role set on it. When the widget containing the softkey actions has focus, its softkeys should appear in the user interface. Softkeys are discovered by traversing the widget hierarchy so it is possible to define a single set of softkeys that are present at all times by calling PySide.QtGui.QWidget.addAction() for a given top level widget.

On some platforms, this concept overlaps with QMenuBar such that if no other softkeys are found and the top level widget is a PySide.QtGui.QMainWindow containing a PySide.QtGui.QMenuBar , the menubar actions may appear on one of the softkeys.

Note: Currently softkeys are only supported on the Symbian Platform.

class PySide.QtGui.QWidget([parent=None[, f=0]])
Parameters:
PySide.QtGui.QWidget.RenderFlag

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

Constant Description
QWidget.DrawWindowBackground If you enable this option, the widget’s background is rendered into the target even if PySide.QtGui.QWidget.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 QWidget.mask() is ignored when rendering into the target. By default, this option is disabled.
PySide.QtGui.QWidget.acceptDrops()
Return type:PySide.QtCore.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 ( PySide.QtGui.QWidget.windowType() == Qt.Desktop ), this may fail if another application is using the desktop; you can call PySide.QtGui.QWidget.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

PySide.QtGui.QWidget.accessibleDescription()
Return type:unicode

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

By default, this property contains an empty string.

See also

QAccessibleInterface.text()

PySide.QtGui.QWidget.accessibleName()
Return type:unicode

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

This property is used by accessible clients to identify, find, or announce the widget for accessible clients.

By default, this property contains an empty string.

See also

QAccessibleInterface.text()

PySide.QtGui.QWidget.actionEvent(event)
Parameters:eventPySide.QtGui.QActionEvent

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

PySide.QtGui.QWidget.actions()
Return type:

Returns the (possibly empty) list of this widget’s actions.

PySide.QtGui.QWidget.activateWindow()

Sets the top-level widget containing this widget to be the active window.

An active window is a visible top-level window that has the keyboard input focus.

This function performs the same operation as clicking the mouse on the title bar of a top-level window. On X11, the result depends on the Window Manager. If you want to ensure that the window is stacked on top as well you should also call raise() . Note that the window must be visible, otherwise PySide.QtGui.QWidget.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.

PySide.QtGui.QWidget.addAction(action)
Parameters:actionPySide.QtGui.QAction

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

All QWidgets have a list of PySide.QtGui.QAction s, however they can be represented graphically in many different ways. The default use of the PySide.QtGui.QAction list (as returned by PySide.QtGui.QWidget.actions() ) is to create a context PySide.QtGui.QMenu .

A PySide.QtGui.QWidget should only have one of each action and adding an action it already has will not cause the same action to be in the widget twice.

The ownership of action is not transferred to this PySide.QtGui.QWidget .

PySide.QtGui.QWidget.addActions(actions)
Parameters:actions
PySide.QtGui.QWidget.adjustSize()

Adjusts the size of the widget to fit its contents.

This function uses PySide.QtGui.QWidget.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 PySide.QtGui.QWidget.sizeHint() is less than (200, 100) and the size policy is expanding , the window will be at least (200, 100). The maximum size of a window is 2/3 of the screen’s width and height.

PySide.QtGui.QWidget.autoFillBackground()
Return type:PySide.QtCore.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

Qt.WA_OpaquePaintEvent Qt.WA_NoSystemBackground Transparency and Double Buffering

PySide.QtGui.QWidget.backgroundRole()
Return type:PySide.QtGui.QPalette.ColorRole

Returns the background role of the widget.

The background role defines the brush from the widget’s PySide.QtGui.QWidget.palette() that is used to render the background.

If no explicit background role is set, the widget inherts its parent widget’s background role.

PySide.QtGui.QWidget.baseSize()
Return type:PySide.QtCore.QSize

This property holds the base size of the widget.

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

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

PySide.QtGui.QWidget.changeEvent(event)
Parameters:eventPySide.QtCore.QEvent

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 .

PySide.QtGui.QWidget.childAt(p)
Parameters:pPySide.QtCore.QPoint
Return type:PySide.QtGui.QWidget

This is an overloaded function.

Returns the visible child widget at point p in the widget’s own coordinate system.

PySide.QtGui.QWidget.childAt(x, y)
Parameters:
  • xPySide.QtCore.int
  • yPySide.QtCore.int
Return type:

PySide.QtGui.QWidget

Returns the visible child widget at the position (x , y ) in the widget’s coordinate system. If there is no visible child widget at the specified position, the function returns 0.

PySide.QtGui.QWidget.childrenRect()
Return type:PySide.QtCore.QRect

This property holds the bounding rectangle of the widget’s children.

Hidden children are excluded.

By default, for a widget with no children, this property contains a rectangle with zero width and height located at the origin.

PySide.QtGui.QWidget.childrenRegion()
Return type:PySide.QtGui.QRegion

This property holds the combined region occupied by the widget’s children.

Hidden children are excluded.

By default, for a widget with no children, this property contains an empty region.

PySide.QtGui.QWidget.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 is about to lose the focus.

This widget must enable focus setting in order to get the keyboard input focus, i.e. it must call PySide.QtGui.QWidget.setFocusPolicy() .

PySide.QtGui.QWidget.clearMask()

Removes any mask set by PySide.QtGui.QWidget.setMask() .

PySide.QtGui.QWidget.close()
Return type:PySide.QtCore.bool

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

First it sends the widget a PySide.QtGui.QCloseEvent . The widget is hidden if it accepts the close event. If it ignores the event, nothing happens. The default implementation of QWidget.closeEvent() accepts the close event.

If the widget has the Qt.WA_DeleteOnClose flag, the widget is also deleted. A close events is delivered to the widget no matter if the widget is visible or not.

The QApplication.lastWindowClosed() signal is emitted when the last visible primary window (i.e. window with no parent) with the Qt.WA_QuitOnClose attribute set is closed. By default this attribute is set for all widgets except transient windows such as splash screens, tool windows, and popup menus.

PySide.QtGui.QWidget.closeEvent(event)
Parameters:eventPySide.QtGui.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 PySide.QtCore.QEvent.ignore() on all events.

Main window applications typically use reimplementations of this function to check whether the user’s work has been saved and ask for permission before closing. For example, the Application Example uses a helper function to determine whether or not to close the window:

def closeEvent(self, event):
    if maybeSave():
        writeSettings()
        event.accept()
    else:
        event.ignore()

See also

PySide.QtGui.QWidget.event() PySide.QtGui.QWidget.hide() PySide.QtGui.QWidget.close() PySide.QtGui.QCloseEvent Application Example

PySide.QtGui.QWidget.contentsMargins()
Return type:PySide.QtCore.QMargins

The contentsMargins function returns the widget’s contents margins.

PySide.QtGui.QWidget.contentsRect()
Return type:PySide.QtCore.QRect

Returns the area inside the widget’s margins.

PySide.QtGui.QWidget.contextMenuEvent(event)
Parameters:eventPySide.QtGui.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 PySide.QtGui.QWidget.contextMenuPolicy() is Qt.DefaultContextMenu .

The default implementation ignores the context event. See the PySide.QtGui.QContextMenuEvent documentation for more details.

PySide.QtGui.QWidget.contextMenuPolicy()
Return type:PySide.QtCore.Qt.ContextMenuPolicy

This property holds how the widget shows a context menu.

The default value of this property is Qt.DefaultContextMenu , which means the PySide.QtGui.QWidget.contextMenuEvent() handler is called. Other values are Qt.NoContextMenu , Qt.PreventContextMenu , Qt.ActionsContextMenu , and Qt.CustomContextMenu . With Qt.CustomContextMenu , the signal PySide.QtGui.QWidget.customContextMenuRequested() is emitted.

PySide.QtGui.QWidget.createWinId()

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

PySide.QtGui.QWidget.cursor()
Return type:PySide.QtGui.QCursor

This property holds the cursor shape for this widget.

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

An editor widget might use an I-beam cursor:

widget.setCursor(Qt.IBeamCursor)

If no cursor has been set, or after a call to PySide.QtGui.QWidget.unsetCursor() , the parent’s cursor is used.

By default, this property contains a cursor with the Qt.ArrowCursor shape.

Some underlying window implementations will reset the cursor if it leaves a widget even if the mouse is grabbed. If you want to have a cursor set for all widgets, even when outside the window, consider QApplication.setOverrideCursor() .

PySide.QtGui.QWidget.customContextMenuRequested(pos)
Parameters:posPySide.QtCore.QPoint
PySide.QtGui.QWidget.destroy([destroyWindow=true[, destroySubWindows=true]])
Parameters:
  • destroyWindowPySide.QtCore.bool
  • destroySubWindowsPySide.QtCore.bool

Frees up window system resources. Destroys the widget window if destroyWindow is true.

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

This function is usually called from the PySide.QtGui.QWidget destructor.

PySide.QtGui.QWidget.dragEnterEvent(event)
Parameters:eventPySide.QtGui.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.

PySide.QtGui.QWidget.dragLeaveEvent(event)
Parameters:eventPySide.QtGui.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.

PySide.QtGui.QWidget.dragMoveEvent(event)
Parameters:eventPySide.QtGui.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.

PySide.QtGui.QWidget.dropEvent(event)
Parameters:eventPySide.QtGui.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.

PySide.QtGui.QWidget.effectiveWinId()
Return type:long

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.

PySide.QtGui.QWidget.ensurePolished()

Ensures that the widget has been polished by PySide.QtGui.QStyle (i.e., has a proper font and palette).

PySide.QtGui.QWidget calls this function after it has been fully constructed but before it is shown the very first time. You can call this function if you want to ensure that the widget is polished before doing an operation, e.g., the correct font size might be needed in the widget’s PySide.QtGui.QWidget.sizeHint() reimplementation. Note that this function is called from the default implementation of PySide.QtGui.QWidget.sizeHint() .

Polishing is useful for final initialization that must happen after all constructors (from base classes as well as from subclasses) have been called.

If you need to change some settings when a widget is polished, reimplement PySide.QtGui.QWidget.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., PySide.QtGui.QWidget.sizeHint() ).

See also

PySide.QtGui.QWidget.event()

PySide.QtGui.QWidget.enterEvent(event)
Parameters:eventPySide.QtCore.QEvent

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.

PySide.QtGui.QWidget.focusInEvent(event)
Parameters:eventPySide.QtGui.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 parameter

A widget normally must PySide.QtGui.QWidget.setFocusPolicy() to something other than Qt.NoFocus in order to receive focus events. (Note that the application programmer can call PySide.QtGui.QWidget.setFocus() on any widget, even those that do not normally accept focus.)

The default implementation updates the widget (except for windows that do not specify a PySide.QtGui.QWidget.focusPolicy() ).

PySide.QtGui.QWidget.focusNextChild()
Return type:PySide.QtCore.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.

PySide.QtGui.QWidget.focusNextPrevChild(next)
Parameters:nextPySide.QtCore.bool
Return type:PySide.QtCore.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, if next is false, it searches backward.

Sometimes, you will want to reimplement this function. For example, a web browser might reimplement it to move its “current active link” forward or backward, and call PySide.QtGui.QWidget.focusNextPrevChild() only when it reaches the last or first link on the “page”.

Child widgets call PySide.QtGui.QWidget.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.

PySide.QtGui.QWidget.focusOutEvent(event)
Parameters:eventPySide.QtGui.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 PySide.QtGui.QWidget.setFocusPolicy() to something other than Qt.NoFocus in order to receive focus events. (Note that the application programmer can call PySide.QtGui.QWidget.setFocus() on any widget, even those that do not normally accept focus.)

The default implementation updates the widget (except for windows that do not specify a PySide.QtGui.QWidget.focusPolicy() ).

PySide.QtGui.QWidget.focusPolicy()
Return type:PySide.QtCore.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 PySide.QtGui.QLineEdit constructor calls setFocusPolicy( Qt.StrongFocus ).

If the widget has a focus proxy, then the focus policy will be propagated to it.

PySide.QtGui.QWidget.focusPreviousChild()
Return type:PySide.QtCore.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.

PySide.QtGui.QWidget.focusProxy()
Return type:PySide.QtGui.QWidget

Returns the focus proxy, or 0 if there is no focus proxy.

PySide.QtGui.QWidget.focusWidget()
Return type:PySide.QtGui.QWidget

Returns the last child of this widget that setFocus had been called on. For top level widgets this is the widget that will get focus in case this window gets activated

This is not the same as QApplication.focusWidget() , which returns the focus widget in the currently active window.

PySide.QtGui.QWidget.font()
Return type:PySide.QtGui.QFont

This property holds the font currently set for the widget.

This property describes the widget’s requested font. The font is used by the widget’s style when rendering standard components, and is available as a means to ensure that custom widgets can maintain consistency with the native platform’s look and feel. It’s common that different platforms, or different styles, define different fonts for an application.

When you assign a new font to a widget, the properties from this font are combined with the widget’s default font to form the widget’s final font. You can call PySide.QtGui.QWidget.fontInfo() to get a copy of the widget’s final font. The final font is also used to initialize PySide.QtGui.QPainter ‘s font.

The default depends on the system environment. PySide.QtGui.QApplication maintains a system/theme font which serves as a default for all widgets. There may also be special font defaults for certain types of widgets. You can also define default fonts for widgets yourself by passing a custom font and the name of a widget to QApplication.setFont() . Finally, the font is matched against Qt’s font database to find the best match.

PySide.QtGui.QWidget propagates explicit font properties from parent to child. If you change a specific property on a font and assign that font to a widget, that property will propagate to all the widget’s children, overriding any system defaults for that property. Note that fonts by default don’t propagate to windows (see PySide.QtGui.QWidget.isWindow() ) unless the Qt.WA_WindowPropagation attribute is enabled.

PySide.QtGui.QWidget ‘s font propagation is similar to its palette propagation.

The current style, which is used to render the content of all standard Qt widgets, is free to choose to use the widget font, or in some cases, to ignore it (partially, or completely). In particular, certain styles like GTK style, Mac style, Windows XP, and Vista style, apply special modifications to the widget font to match the platform’s native look and feel. Because of this, assigning properties to a widget’s font is not guaranteed to change the appearance of the widget. Instead, you may choose to apply a PySide.QtGui.QWidget.styleSheet() .

Note

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

PySide.QtGui.QWidget.fontInfo()
Return type:PySide.QtGui.QFontInfo

Returns the font info for the widget’s current font. Equivalent to QFontInto(widget-> PySide.QtGui.QWidget.font() ).

PySide.QtGui.QWidget.fontMetrics()
Return type:PySide.QtGui.QFontMetrics

Returns the font metrics for the widget’s current font. Equivalent to PySide.QtGui.QFontMetrics (widget-> PySide.QtGui.QWidget.font() ).

PySide.QtGui.QWidget.foregroundRole()
Return type:PySide.QtGui.QPalette.ColorRole

Returns the foreground role.

The foreground role defines the color from the widget’s PySide.QtGui.QWidget.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.

PySide.QtGui.QWidget.frameGeometry()
Return type:PySide.QtCore.QRect

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.

PySide.QtGui.QWidget.frameSize()
Return type:PySide.QtCore.QSize

This property holds the size of the widget including any window frame.

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

PySide.QtGui.QWidget.geometry()
Return type:PySide.QtCore.QRect

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

When changing the geometry, the widget, if visible, receives a move event ( PySide.QtGui.QWidget.moveEvent() ) and/or a resize event ( PySide.QtGui.QWidget.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 PySide.QtGui.QWidget.minimumSize() and PySide.QtGui.QWidget.maximumSize() .

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.

PySide.QtGui.QWidget.getContentsMargins()

Returns the widget’s contents margins for left , top , right , and bottom .

PySide.QtGui.QWidget.grabGesture(type[, flags=Qt.GestureFlags()])
Parameters:
  • typePySide.QtCore.Qt.GestureType
  • flagsPySide.QtCore.Qt.GestureFlags
PySide.QtGui.QWidget.grabKeyboard()

Grabs the keyboard input.

This widget receives all keyboard events until PySide.QtGui.QWidget.releaseKeyboard() is called; other widgets get no keyboard events at all. Mouse events are not affected. Use PySide.QtGui.QWidget.grabMouse() if you want to grab that.

The focus widget is not affected, except that it doesn’t receive any keyboard events. PySide.QtGui.QWidget.setFocus() moves the focus as usual, but the new focus widget receives keyboard events only after PySide.QtGui.QWidget.releaseKeyboard() is called.

If a different widget is currently grabbing keyboard input, that widget’s grab is released first.

PySide.QtGui.QWidget.grabMouse()

Grabs the mouse input.

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

Warning

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

It is almost never necessary to grab the mouse when using Qt, as Qt grabs and releases it sensibly. In particular, Qt grabs the mouse when a mouse button is pressed and keeps it until the last button is released.

Note

Only visible widgets can grab mouse input. If PySide.QtGui.QWidget.isVisible() returns false for a widget, that widget cannot call PySide.QtGui.QWidget.grabMouse() .

Note

(Mac OS X developers) For Cocoa , calling PySide.QtGui.QWidget.grabMouse() on a widget only works when the mouse is inside the frame of that widget. For Carbon , it works outside the widget’s frame as well, like for Windows and X11.

PySide.QtGui.QWidget.grabMouse(arg__1)
Parameters:arg__1PySide.QtGui.QCursor

This function overloads PySide.QtGui.QWidget.grabMouse() .

Grabs the mouse input and changes the cursor shape.

The cursor will assume shape cursor (for as long as the mouse focus is grabbed) and this widget will be the only one to receive mouse events until PySide.QtGui.QWidget.releaseMouse() is called().

Warning

Grabbing the mouse might lock the terminal.

Note

(Mac OS X developers) See the note in QWidget.grabMouse() .

PySide.QtGui.QWidget.grabShortcut(key[, context=Qt.WindowShortcut])
Parameters:
Return type:

PySide.QtCore.int

PySide.QtGui.QWidget.graphicsEffect()
Return type:PySide.QtGui.QGraphicsEffect

The graphicsEffect function returns a pointer to the widget’s graphics effect.

If the widget has no graphics effect, 0 is returned.

PySide.QtGui.QWidget.graphicsProxyWidget()
Return type:PySide.QtGui.QGraphicsProxyWidget

Returns the proxy widget for the corresponding embedded widget in a graphics view; otherwise returns 0.

PySide.QtGui.QWidget.hasFocus()
Return type:PySide.QtCore.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 QApplication.focusWidget() refers to the widget.

PySide.QtGui.QWidget.hasMouseTracking()
Return type:PySide.QtCore.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.

PySide.QtGui.QWidget.heightForWidth(arg__1)
Parameters:arg__1PySide.QtCore.int
Return type:PySide.QtCore.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.

PySide.QtGui.QWidget.hide()

Hides the widget. This function is equivalent to setVisible(false).

Note

If you are working with PySide.QtGui.QDialog or its subclasses and you invoke the PySide.QtGui.QWidget.show() function after this function, the dialog will be displayed in its original position.

PySide.QtGui.QWidget.hideEvent(event)
Parameters:eventPySide.QtGui.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 PySide.QtGui.QWidget.isVisible() .

See also

visible() PySide.QtGui.QWidget.event() PySide.QtGui.QHideEvent

PySide.QtGui.QWidget.inputContext()
Return type:PySide.QtGui.QInputContext

This function returns the PySide.QtGui.QInputContext for this widget. By default the input context is inherited from the widgets parent. For toplevels it is inherited from PySide.QtGui.QApplication .

You can override this and set a special input context for this widget by using the PySide.QtGui.QWidget.setInputContext() method.

PySide.QtGui.QWidget.inputMethodEvent(event)
Parameters:eventPySide.QtGui.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 PySide.QtGui.QWidget.setAttribute() function) in order to receive input method events.

The default implementation calls event->ignore(), which rejects the Input Method event. See the PySide.QtGui.QInputMethodEvent documentation for more details.

See also

PySide.QtGui.QWidget.event() PySide.QtGui.QInputMethodEvent

PySide.QtGui.QWidget.inputMethodHints()
Return type:PySide.QtCore.Qt.InputMethodHints

This property holds What input method specific hints the widget has..

This is only relevant for input widgets. It is used by the input method to retrieve hints as to how the input method should operate. For example, if the Qt.ImhFormattedNumbersOnly flag is set, the input method may change its visual components to reflect that only numbers can be entered.

Note

The flags are only hints, so the particular input method implementation is free to ignore them. If you want to be sure that a certain type of characters are entered, you should also set a PySide.QtGui.QValidator on the widget.

The default value is Qt.ImhNone .

PySide.QtGui.QWidget.inputMethodQuery(arg__1)
Parameters:arg__1PySide.QtCore.Qt.InputMethodQuery
Return type:object
PySide.QtGui.QWidget.insertAction(before, action)
Parameters:

Inserts the action action to this widget’s list of actions, before the action before . It appends the action if before is 0 or before is not a valid action for this widget.

A PySide.QtGui.QWidget should only have one of each action.

PySide.QtGui.QWidget.insertActions(before, actions)
Parameters:
PySide.QtGui.QWidget.isActiveWindow()
Return type:PySide.QtCore.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.

PySide.QtGui.QWidget.isAncestorOf(child)
Parameters:childPySide.QtGui.QWidget
Return type:PySide.QtCore.bool

Returns true if this widget is a parent, (or grandparent and so on to any level), of the given child , and both widgets are within the same window; otherwise returns false.

PySide.QtGui.QWidget.isEnabled()
Return type:PySide.QtCore.bool

This property holds whether the widget is enabled.

An enabled widget handles keyboard and mouse events; a disabled widget does not.

Some widgets display themselves differently when they are disabled. For example a button might draw its label grayed out. If your widget needs to know when it becomes enabled or disabled, you can use the PySide.QtGui.QWidget.changeEvent() with type QEvent.EnabledChange .

Disabling a widget implicitly disables all its children. Enabling respectively enables all child widgets unless they have been explicitly disabled.

By default, this property is true.

PySide.QtGui.QWidget.isEnabledTo(arg__1)
Parameters:arg__1PySide.QtGui.QWidget
Return type:PySide.QtCore.bool

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

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

isEnabledTo(0) is equivalent to PySide.QtGui.QWidget.isEnabled() .

PySide.QtGui.QWidget.isFullScreen()
Return type:PySide.QtCore.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

PySide.QtGui.QWidget.windowState() minimized() maximized()

PySide.QtGui.QWidget.isHidden()
Return type:PySide.QtCore.bool

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

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

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

PySide.QtGui.QWidget.isHidden() implies ! PySide.QtGui.QWidget.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,
  • PySide.QtGui.QWidget.hide() or setVisible(false) was called.
PySide.QtGui.QWidget.isLeftToRight()
Return type:PySide.QtCore.bool
PySide.QtGui.QWidget.isMaximized()
Return type:PySide.QtCore.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.

PySide.QtGui.QWidget.isMinimized()
Return type:PySide.QtCore.bool

This property holds whether this widget is minimized (iconified).

This property is only relevant for windows.

By default, this property is false.

PySide.QtGui.QWidget.isModal()
Return type:PySide.QtCore.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.

PySide.QtGui.QWidget.isRightToLeft()
Return type:PySide.QtCore.bool
PySide.QtGui.QWidget.isVisible()
Return type:PySide.QtCore.bool

This property holds whether the widget is visible.

Calling setVisible(true) or PySide.QtGui.QWidget.show() sets the widget to visible status if all its parent widgets up to the window are visible. If an ancestor is not visible, the widget won’t become visible until all its ancestors are shown. If its size or position has changed, Qt guarantees that a widget gets move and resize events just before it is shown. If the widget has not been resized yet, Qt will adjust the widget’s size to a useful default using PySide.QtGui.QWidget.adjustSize() .

Calling setVisible(false) or PySide.QtGui.QWidget.hide() hides a widget explicitly. An explicitly hidden widget will never become visible, even if all its ancestors become visible, unless you show it.

A widget receives show and hide events when its visibility status changes. Between a hide and a show event, there is no need to waste CPU cycles preparing or displaying information to the user. A video application, for example, might simply stop generating new frames.

A widget that happens to be obscured by other windows on the screen is considered to be visible. The same applies to iconified windows and windows that exist on another virtual desktop (on platforms that support this concept). A widget receives spontaneous show and hide events when its mapping status is changed by the window system, e.g. a spontaneous hide event when the user minimizes the window, and a spontaneous show event when the window is restored again.

You almost never have to reimplement the PySide.QtGui.QWidget.setVisible() function. If you need to change some settings before a widget is shown, use PySide.QtGui.QWidget.showEvent() instead. If you need to do some delayed initialization use the Polish event delivered to the PySide.QtGui.QWidget.event() function.

PySide.QtGui.QWidget.isVisibleTo(arg__1)
Parameters:arg__1PySide.QtGui.QWidget
Return type:PySide.QtCore.bool

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

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

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

isVisibleTo(0) is identical to PySide.QtGui.QWidget.isVisible() .

PySide.QtGui.QWidget.isWindow()
Return type:PySide.QtCore.bool

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

A window is a widget that isn’t visually the child of any other widget and that usually has a frame and a 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.

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

PySide.QtGui.QWidget.isWindowModified()
Return type:PySide.QtCore.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 Mac OS X the close button will have a modified look; on other platforms, the window title will have an ‘*’ (asterisk).

The window title must contain a “[*]” placeholder, which indicates where the ‘*’ should appear. Normally, it should appear right after the file name (e.g., “document1.txt[*] - Text Editor”). If the window isn’t modified, the placeholder is simply removed.

Note that if a widget is set as modified, all its ancestors will also be set as modified. However, if you call setWindowModified(false) on a widget, this will not propagate to its parent because other children of the parent might have been modified.

See also

PySide.QtGui.QWidget.windowTitle() Application Example SDI Example MDI Example

PySide.QtGui.QWidget.keyPressEvent(event)
Parameters:eventPySide.QtGui.QKeyEvent

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

A widget must call PySide.QtGui.QWidget.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 Esc. Otherwise the event is ignored, so that the widget’s parent can interpret it.

Note that PySide.QtGui.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.

PySide.QtGui.QWidget.keyReleaseEvent(event)
Parameters:eventPySide.QtGui.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 and have focus in order to receive a key release event.

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

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

Note that PySide.QtGui.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.

static PySide.QtGui.QWidget.keyboardGrabber()
Return type:PySide.QtGui.QWidget

Returns the widget that is currently grabbing the keyboard input.

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

PySide.QtGui.QWidget.languageChange()
PySide.QtGui.QWidget.layout()
Return type:PySide.QtGui.QLayout

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

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

PySide.QtGui.QWidget.layoutDirection()
Return type:PySide.QtCore.Qt.LayoutDirection

This property holds the layout direction for this widget.

By default, this property is set to Qt.LeftToRight .

When the layout direction is set on a widget, it will propagate to the widget’s children, but not to a child that is a window and not to a child for which PySide.QtGui.QWidget.setLayoutDirection() has been explicitly called. Also, child widgets added afterPySide.QtGui.QWidget.setLayoutDirection() has been called for the parent do not inherit the parent’s layout direction.

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

PySide.QtGui.QWidget.leaveEvent(event)
Parameters:eventPySide.QtCore.QEvent

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.

PySide.QtGui.QWidget.locale()
Return type:PySide.QtCore.QLocale

This property holds the widget’s locale.

As long as no special locale has been set, this is either the parent’s locale or (if this widget is a top level widget), the default locale.

If the widget displays dates or numbers, these should be formatted using the widget’s locale.

See also

PySide.QtCore.QLocale QLocale.setDefault()

PySide.QtGui.QWidget.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.

PySide.QtGui.QWidget.mapFrom(arg__1, arg__2)
Parameters:
Return type:

PySide.QtCore.QPoint

Translates the widget coordinate pos from the coordinate system of parent to this widget’s coordinate system. The parent must not be 0 and must be a parent of the calling widget.

PySide.QtGui.QWidget.mapFromGlobal(arg__1)
Parameters:arg__1PySide.QtCore.QPoint
Return type:PySide.QtCore.QPoint

Translates the global screen coordinate pos to widget coordinates.

PySide.QtGui.QWidget.mapFromParent(arg__1)
Parameters:arg__1PySide.QtCore.QPoint
Return type:PySide.QtCore.QPoint

Translates the parent widget coordinate pos to widget coordinates.

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

PySide.QtGui.QWidget.mapTo(arg__1, arg__2)
Parameters:
Return type:

PySide.QtCore.QPoint

Translates the widget coordinate pos to the coordinate system of parent . The parent must not be 0 and must be a parent of the calling widget.

PySide.QtGui.QWidget.mapToGlobal(arg__1)
Parameters:arg__1PySide.QtCore.QPoint
Return type:PySide.QtCore.QPoint

Translates the widget coordinate pos to global screen coordinates. For example, mapToGlobal(QPoint(0,0)) would give the global coordinates of the top-left pixel of the widget.

PySide.QtGui.QWidget.mapToParent(arg__1)
Parameters:arg__1PySide.QtCore.QPoint
Return type:PySide.QtCore.QPoint

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

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

PySide.QtGui.QWidget.mask()
Return type:PySide.QtGui.QRegion

Returns the mask currently set on a widget. If no mask is set the return value will be an empty region.

PySide.QtGui.QWidget.maximumHeight()
Return type:PySide.QtCore.int

This property holds the widget’s maximum height in pixels.

This property corresponds to the height held by the PySide.QtGui.QWidget.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.

PySide.QtGui.QWidget.maximumSize()
Return type:PySide.QtCore.QSize

This property holds the widget’s maximum size in pixels.

The widget cannot be resized to a larger size than the maximum widget size.

By default, this property contains a size in which both width and height have values of 16777215.

Note

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

PySide.QtGui.QWidget.maximumWidth()
Return type:PySide.QtCore.int

This property holds the widget’s maximum width in pixels.

This property corresponds to the width held by the PySide.QtGui.QWidget.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.

PySide.QtGui.QWidget.minimumHeight()
Return type:PySide.QtCore.int

This property holds the widget’s minimum height in pixels.

This property corresponds to the height held by the PySide.QtGui.QWidget.minimumSize() property.

By default, this property has a value of 0.

PySide.QtGui.QWidget.minimumSize()
Return type:PySide.QtCore.QSize

This property holds the widget’s minimum size.

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

The minimum size set by this function will override the minimum size defined by PySide.QtGui.QLayout . In order to unset the minimum size, use a value of QSize(0, 0) .

By default, this property contains a size with zero width and height.

PySide.QtGui.QWidget.minimumSizeHint()
Return type:PySide.QtCore.QSize

This property holds the recommended minimum size for the widget.

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

The default implementation of PySide.QtGui.QWidget.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 PySide.QtGui.QWidget.minimumSizeHint() .

PySide.QtGui.QLayout will never resize a widget to a size smaller than the minimum size hint unless PySide.QtGui.QWidget.minimumSize() is set or the size policy is set to QSizePolicy::Ignore. If PySide.QtGui.QWidget.minimumSize() is set, the minimum size hint will be ignored.

PySide.QtGui.QWidget.minimumWidth()
Return type:PySide.QtCore.int

This property holds the widget’s minimum width in pixels.

This property corresponds to the width held by the PySide.QtGui.QWidget.minimumSize() property.

By default, this property has a value of 0.

PySide.QtGui.QWidget.mouseDoubleClickEvent(event)
Parameters:eventPySide.QtGui.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 generates a normal mouse press event.

Note

The widget will also receive mouse press and mouse release events in addition to the double click event. It is up to the developer to ensure that the application interprets these events correctly.

static PySide.QtGui.QWidget.mouseGrabber()
Return type:PySide.QtGui.QWidget

Returns the widget that is currently grabbing the mouse input.

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

PySide.QtGui.QWidget.mouseMoveEvent(event)
Parameters:eventPySide.QtGui.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 QToolTip.showText() instead of PySide.QtGui.QWidget.setToolTip() in your implementation of PySide.QtGui.QWidget.mouseMoveEvent() .

PySide.QtGui.QWidget.mousePressEvent(event)
Parameters:eventPySide.QtGui.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 PySide.QtGui.QWidget.mousePressEvent() the PySide.QtGui.QWidget.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.

PySide.QtGui.QWidget.mouseReleaseEvent(event)
Parameters:eventPySide.QtGui.QMouseEvent

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

PySide.QtGui.QWidget.move(x, y)
Parameters:
  • xPySide.QtCore.int
  • yPySide.QtCore.int

This is an overloaded function.

This corresponds to move( PySide.QtCore.QPoint (x , y )).

PySide.QtGui.QWidget.move(arg__1)
Parameters:arg__1PySide.QtCore.QPoint

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 ( PySide.QtGui.QWidget.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 PySide.QtGui.QWidget.move() or PySide.QtGui.QWidget.setGeometry() inside PySide.QtGui.QWidget.moveEvent() can lead to infinite recursion.

See the Window Geometry documentation for an overview of geometry issues with windows.

PySide.QtGui.QWidget.moveEvent(event)
Parameters:eventPySide.QtGui.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() .

PySide.QtGui.QWidget.nativeParentWidget()
Return type:PySide.QtGui.QWidget

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

PySide.QtGui.QWidget.nextInFocusChain()
Return type:PySide.QtGui.QWidget

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

PySide.QtGui.QWidget.normalGeometry()
Return type:PySide.QtCore.QRect

This property holds the geometry of the widget as it will appear when shown as a normal (not maximized or full screen) top-level widget.

For child widgets this property always holds an empty rectangle.

By default, this property contains an empty rectangle.

PySide.QtGui.QWidget.overrideWindowFlags(type)
Parameters:typePySide.QtCore.Qt.WindowFlags
PySide.QtGui.QWidget.overrideWindowState(state)
Parameters:statePySide.QtCore.Qt.WindowStates
PySide.QtGui.QWidget.paintEvent(event)
Parameters:eventPySide.QtGui.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. PySide.QtGui.QListView and PySide.QtGui.QTableView do this, for example.

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

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

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

Since Qt 4.0, PySide.QtGui.QWidget automatically double-buffers its painting, so there is no need to write double-buffering code in PySide.QtGui.QWidget.paintEvent() to avoid flicker.

Note for the X11 platform : It is possible to toggle global double buffering by calling qt_x11_set_global_double_buffer() . For example,

...
extern void qt_x11_set_global_double_buffer(bool);
qt_x11_set_global_double_buffer(false);
...

Note

Generally, you should refrain from calling PySide.QtGui.QWidget.update() or PySide.QtGui.QWidget.repaint() inside a PySide.QtGui.QWidget.paintEvent() . For example, calling PySide.QtGui.QWidget.update() or PySide.QtGui.QWidget.repaint() on children inside a paintevent() results in undefined behavior; the child may or may not get a paint event.

Warning

If you are using a custom paint engine without Qt’s backingstore, Qt.WA_PaintOnScreen must be set. Otherwise, QWidget.paintEngine() will never be called; the backingstore will be used instead.

PySide.QtGui.QWidget.palette()
Return type:PySide.QtGui.QPalette

This property holds the widget’s palette.

This property describes the widget’s palette. The palette is used by the widget’s style when rendering standard components, and is available as a means to ensure that custom widgets can maintain consistency with the native platform’s look and feel. It’s common that different platforms, or different styles, have different palettes.

When you assign a new palette to a widget, the color roles from this palette are combined with the widget’s default palette to form the widget’s final palette. The palette entry for the widget’s background role is used to fill the widget’s background (see QWidget.autoFillBackground ), and the foreground role initializes PySide.QtGui.QPainter ‘s pen.

The default depends on the system environment. PySide.QtGui.QApplication maintains a system/theme palette which serves as a default for all widgets. There may also be special palette defaults for certain types of widgets (e.g., on Windows XP and Vista, all classes that derive from PySide.QtGui.QMenuBar have a special default palette). You can also define default palettes for widgets yourself by passing a custom palette and the name of a widget to QApplication.setPalette() . Finally, the style always has the option of polishing the palette as it’s assigned (see QStyle.polish() ).

PySide.QtGui.QWidget propagates explicit palette roles from parent to child. If you assign a brush or color to a specific role on a palette and assign that palette to a widget, that role will propagate to all the widget’s children, overriding any system defaults for that role. Note that palettes by default don’t propagate to windows (see PySide.QtGui.QWidget.isWindow() ) unless the Qt.WA_WindowPropagation attribute is enabled.

PySide.QtGui.QWidget ‘s palette propagation is similar to its font propagation.

The current style, which is used to render the content of all standard Qt widgets, is free to choose colors and brushes from the widget palette, or in some cases, to ignore the palette (partially, or completely). In particular, certain styles like GTK style, Mac style, Windows XP, and Vista style, depend on third party APIs to render the content of widgets, and these styles typically do not follow the palette. Because of this, assigning roles to a widget’s palette is not guaranteed to change the appearance of the widget. Instead, you may choose to apply a PySide.QtGui.QWidget.styleSheet() . You can refer to our Knowledge Base article here for more information.

Warning

Do not use this function in conjunction with Qt Style Sheets . When using style sheets, the palette of a widget can be customized using the “color”, “background-color”, “selection-color”, “selection-background-color” and “alternate-background-color”.

PySide.QtGui.QWidget.parentWidget()
Return type:PySide.QtGui.QWidget

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

PySide.QtGui.QWidget.pos()
Return type:PySide.QtCore.QPoint

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 ( PySide.QtGui.QWidget.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 PySide.QtGui.QWidget.move() or PySide.QtGui.QWidget.setGeometry() inside PySide.QtGui.QWidget.moveEvent() can lead to infinite recursion.

See the Window Geometry documentation for an overview of geometry issues with windows.

PySide.QtGui.QWidget.previousInFocusChain()
Return type:PySide.QtGui.QWidget

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

PySide.QtGui.QWidget.raise_()

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

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

Note

When using PySide.QtGui.QWidget.activateWindow() , you can call this function to ensure that the window is stacked on top.

PySide.QtGui.QWidget.rect()
Return type:PySide.QtCore.QRect

This property holds the internal geometry of the widget excluding any window frame.

The rect property equals PySide.QtCore.QRect (0, 0, PySide.QtGui.QWidget.width() , PySide.QtGui.QWidget.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.

PySide.QtGui.QWidget.releaseKeyboard()

Releases the keyboard grab.

PySide.QtGui.QWidget.releaseMouse()

Releases the mouse grab.

PySide.QtGui.QWidget.releaseShortcut(id)
Parameters:idPySide.QtCore.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 PySide.QtGui.QAction or PySide.QtGui.QShortcut to handle shortcuts, since they are easier to use than this low-level function. Note also that this is an expensive operation.

PySide.QtGui.QWidget.removeAction(action)
Parameters:actionPySide.QtGui.QAction

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

PySide.QtGui.QWidget.render(target[, targetOffset=QPoint()[, sourceRegion=QRegion()[, renderFlags=QWidget.RenderFlags(DrawWindowBackground | DrawChildren)]]])
Parameters:
PySide.QtGui.QWidget.render(painter, targetOffset[, sourceRegion=QRegion()[, renderFlags=QWidget.RenderFlags(DrawWindowBackground | DrawChildren)]])
Parameters:
PySide.QtGui.QWidget.repaint(x, y, w, h)
Parameters:
  • xPySide.QtCore.int
  • yPySide.QtCore.int
  • wPySide.QtCore.int
  • hPySide.QtCore.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 with width() - x , and if h is negative, it is replaced width height() - y .

PySide.QtGui.QWidget.repaint(arg__1)
Parameters:arg__1PySide.QtGui.QRegion

This is an overloaded function.

This version repaints a region rgn inside the widget.

PySide.QtGui.QWidget.repaint(arg__1)
Parameters:arg__1PySide.QtCore.QRect

This is an overloaded function.

This version repaints a rectangle rect inside the widget.

PySide.QtGui.QWidget.repaint()

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

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

Warning

If you call PySide.QtGui.QWidget.repaint() in a function which may itself be called from PySide.QtGui.QWidget.paintEvent() , you may get infinite recursion. The PySide.QtGui.QWidget.update() function never causes recursion.

PySide.QtGui.QWidget.resetInputContext()

This function can be called on the widget that currently has focus to reset the input method operating on it.

This function is providing for convenience, instead you should use PySide.QtGui.QInputContext.reset() on the input context that was returned by PySide.QtGui.QWidget.inputContext() .

PySide.QtGui.QWidget.resize(arg__1)
Parameters:arg__1PySide.QtCore.QSize

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 ( PySide.QtGui.QWidget.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 PySide.QtGui.QWidget.minimumSize() and PySide.QtGui.QWidget.maximumSize() .

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

Note

Setting the size to QSize(0, 0) will cause the widget to not appear on screen. This also applies to windows.

PySide.QtGui.QWidget.resize(w, h)
Parameters:
  • wPySide.QtCore.int
  • hPySide.QtCore.int

This is an overloaded function.

This corresponds to resize( PySide.QtCore.QSize (w , h )).

PySide.QtGui.QWidget.resizeEvent(event)
Parameters:eventPySide.QtGui.QResizeEvent

This event handler can be reimplemented in a subclass to receive widget resize events which are passed in the event parameter. When PySide.QtGui.QWidget.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.

PySide.QtGui.QWidget.restoreGeometry(geometry)
Parameters:geometryPySide.QtCore.QByteArray
Return type:PySide.QtCore.bool

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

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

To restore geometry saved using PySide.QtCore.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 QMainWindow.restoreState() to restore the geometry and the state of toolbars and dock widgets.

PySide.QtGui.QWidget.saveGeometry()
Return type:PySide.QtCore.QByteArray

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:

class MyWidget(QWidget):

    self.settings = None

    def closeEvent(event):
        # event is a QCloseEvent
        self.settings = QSettings("MyCompany", "MyApp")
        self.settings.setValue("geometry", self.saveGeometry())
        QWidget.closeEvent(self, event)

See the Window Geometry documentation for an overview of geometry issues with windows.

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

PySide.QtGui.QWidget.scroll(dx, dy)
Parameters:
  • dxPySide.QtCore.int
  • dyPySide.QtCore.int

Scrolls the widget including its children dx pixels to the right and dy downward. Both dx and dy may be negative.

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

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

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

See also

Transparency and Double Buffering

PySide.QtGui.QWidget.scroll(dx, dy, arg__3)
Parameters:

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.

PySide.QtGui.QWidget.setAcceptDrops(on)
Parameters:onPySide.QtCore.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 ( PySide.QtGui.QWidget.windowType() == Qt.Desktop ), this may fail if another application is using the desktop; you can call PySide.QtGui.QWidget.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

PySide.QtGui.QWidget.setAccessibleDescription(description)
Parameters:description – unicode

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

By default, this property contains an empty string.

See also

QAccessibleInterface.text()

PySide.QtGui.QWidget.setAccessibleName(name)
Parameters:name – unicode

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

This property is used by accessible clients to identify, find, or announce the widget for accessible clients.

By default, this property contains an empty string.

See also

QAccessibleInterface.text()

PySide.QtGui.QWidget.setAttribute(arg__1[, on=true])
Parameters:
  • arg__1PySide.QtCore.Qt.WidgetAttribute
  • onPySide.QtCore.bool
PySide.QtGui.QWidget.setAutoFillBackground(enabled)
Parameters:enabledPySide.QtCore.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

Qt.WA_OpaquePaintEvent Qt.WA_NoSystemBackground Transparency and Double Buffering

PySide.QtGui.QWidget.setBackgroundRole(arg__1)
Parameters:arg__1PySide.QtGui.QPalette.ColorRole
PySide.QtGui.QWidget.setBaseSize(arg__1)
Parameters:arg__1PySide.QtCore.QSize

This property holds the base size of the widget.

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

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

PySide.QtGui.QWidget.setBaseSize(basew, baseh)
Parameters:
  • basewPySide.QtCore.int
  • basehPySide.QtCore.int

This is an overloaded function.

This corresponds to setBaseSize( PySide.QtCore.QSize (basew , baseh )). Sets the widgets base size to width basew and height baseh .

PySide.QtGui.QWidget.setContentsMargins(left, top, right, bottom)
Parameters:
  • leftPySide.QtCore.int
  • topPySide.QtCore.int
  • rightPySide.QtCore.int
  • bottomPySide.QtCore.int

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

Changing the margins will trigger a PySide.QtGui.QWidget.resizeEvent() .

PySide.QtGui.QWidget.setContentsMargins(margins)
Parameters:marginsPySide.QtCore.QMargins

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 PySide.QtGui.QWidget.resizeEvent() .

PySide.QtGui.QWidget.setContextMenuPolicy(policy)
Parameters:policyPySide.QtCore.Qt.ContextMenuPolicy

This property holds how the widget shows a context menu.

The default value of this property is Qt.DefaultContextMenu , which means the PySide.QtGui.QWidget.contextMenuEvent() handler is called. Other values are Qt.NoContextMenu , Qt.PreventContextMenu , Qt.ActionsContextMenu , and Qt.CustomContextMenu . With Qt.CustomContextMenu , the signal PySide.QtGui.QWidget.customContextMenuRequested() is emitted.

PySide.QtGui.QWidget.setCursor(arg__1)
Parameters:arg__1PySide.QtGui.QCursor

This property holds the cursor shape for this widget.

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

An editor widget might use an I-beam cursor:

widget.setCursor(Qt.IBeamCursor)

If no cursor has been set, or after a call to PySide.QtGui.QWidget.unsetCursor() , the parent’s cursor is used.

By default, this property contains a cursor with the Qt.ArrowCursor shape.

Some underlying window implementations will reset the cursor if it leaves a widget even if the mouse is grabbed. If you want to have a cursor set for all widgets, even when outside the window, consider QApplication.setOverrideCursor() .

PySide.QtGui.QWidget.setDisabled(arg__1)
Parameters:arg__1PySide.QtCore.bool

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

See the enabled() documentation for more information.

PySide.QtGui.QWidget.setEnabled(arg__1)
Parameters:arg__1PySide.QtCore.bool

This property holds whether the widget is enabled.

An enabled widget handles keyboard and mouse events; a disabled widget does not.

Some widgets display themselves differently when they are disabled. For example a button might draw its label grayed out. If your widget needs to know when it becomes enabled or disabled, you can use the PySide.QtGui.QWidget.changeEvent() with type QEvent.EnabledChange .

Disabling a widget implicitly disables all its children. Enabling respectively enables all child widgets unless they have been explicitly disabled.

By default, this property is true.

PySide.QtGui.QWidget.setFixedHeight(h)
Parameters:hPySide.QtCore.int

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

PySide.QtGui.QWidget.setFixedSize(w, h)
Parameters:
  • wPySide.QtCore.int
  • hPySide.QtCore.int

This is an overloaded function.

Sets the width of the widget to w and the height to h .

PySide.QtGui.QWidget.setFixedSize(arg__1)
Parameters:arg__1PySide.QtCore.QSize

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 PySide.QtGui.QLayout .

To remove constraints, set the size to QWIDGETSIZE_MAX() .

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

PySide.QtGui.QWidget.setFixedWidth(w)
Parameters:wPySide.QtCore.int

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

PySide.QtGui.QWidget.setFocus(reason)
Parameters:reasonPySide.QtCore.Qt.FocusReason
PySide.QtGui.QWidget.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 .

PySide.QtGui.QWidget.setFocusPolicy(policy)
Parameters:policyPySide.QtCore.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 PySide.QtGui.QLineEdit constructor calls setFocusPolicy( Qt.StrongFocus ).

If the widget has a focus proxy, then the focus policy will be propagated to it.

PySide.QtGui.QWidget.setFocusProxy(arg__1)
Parameters:arg__1PySide.QtGui.QWidget

Sets the widget’s focus proxy to widget w . If w is 0, the function resets this widget to have no focus proxy.

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

PySide.QtGui.QWidget.setFocusProxy() sets the widget which will actually get focus when “this widget” gets it. If there is a focus proxy, PySide.QtGui.QWidget.setFocus() and PySide.QtGui.QWidget.hasFocus() operate on the focus proxy.

PySide.QtGui.QWidget.setFont(arg__1)
Parameters:arg__1PySide.QtGui.QFont

This property holds the font currently set for the widget.

This property describes the widget’s requested font. The font is used by the widget’s style when rendering standard components, and is available as a means to ensure that custom widgets can maintain consistency with the native platform’s look and feel. It’s common that different platforms, or different styles, define different fonts for an application.

When you assign a new font to a widget, the properties from this font are combined with the widget’s default font to form the widget’s final font. You can call PySide.QtGui.QWidget.fontInfo() to get a copy of the widget’s final font. The final font is also used to initialize PySide.QtGui.QPainter ‘s font.

The default depends on the system environment. PySide.QtGui.QApplication maintains a system/theme font which serves as a default for all widgets. There may also be special font defaults for certain types of widgets. You can also define default fonts for widgets yourself by passing a custom font and the name of a widget to QApplication.setFont() . Finally, the font is matched against Qt’s font database to find the best match.

PySide.QtGui.QWidget propagates explicit font properties from parent to child. If you change a specific property on a font and assign that font to a widget, that property will propagate to all the widget’s children, overriding any system defaults for that property. Note that fonts by default don’t propagate to windows (see PySide.QtGui.QWidget.isWindow() ) unless the Qt.WA_WindowPropagation attribute is enabled.

PySide.QtGui.QWidget ‘s font propagation is similar to its palette propagation.

The current style, which is used to render the content of all standard Qt widgets, is free to choose to use the widget font, or in some cases, to ignore it (partially, or completely). In particular, certain styles like GTK style, Mac style, Windows XP, and Vista style, apply special modifications to the widget font to match the platform’s native look and feel. Because of this, assigning properties to a widget’s font is not guaranteed to change the appearance of the widget. Instead, you may choose to apply a PySide.QtGui.QWidget.styleSheet() .

Note

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

PySide.QtGui.QWidget.setForegroundRole(arg__1)
Parameters:arg__1PySide.QtGui.QPalette.ColorRole
PySide.QtGui.QWidget.setGeometry(x, y, w, h)
Parameters:
  • xPySide.QtCore.int
  • yPySide.QtCore.int
  • wPySide.QtCore.int
  • hPySide.QtCore.int

This is an overloaded function.

This corresponds to setGeometry( PySide.QtCore.QRect (x , y , w , h )).

PySide.QtGui.QWidget.setGeometry(arg__1)
Parameters:arg__1PySide.QtCore.QRect

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

When changing the geometry, the widget, if visible, receives a move event ( PySide.QtGui.QWidget.moveEvent() ) and/or a resize event ( PySide.QtGui.QWidget.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 PySide.QtGui.QWidget.minimumSize() and PySide.QtGui.QWidget.maximumSize() .

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.

PySide.QtGui.QWidget.setGraphicsEffect(effect)
Parameters:effectPySide.QtGui.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, PySide.QtGui.QWidget will delete the existing effect before installing the new effect .

If effect is the installed on a different widget, PySide.QtGui.QWidget.setGraphicsEffect() will remove the effect from the widget and install it on this widget.

PySide.QtGui.QWidget takes ownership of effect .

Note

This function will apply the effect on itself and all its children.

PySide.QtGui.QWidget.setHidden(hidden)
Parameters:hiddenPySide.QtCore.bool

Convenience function, equivalent to setVisible(!``hidden`` ).

PySide.QtGui.QWidget.setInputContext(arg__1)
Parameters:arg__1PySide.QtGui.QInputContext

This function sets the input context context on this widget.

Qt takes ownership of the given input context .

PySide.QtGui.QWidget.setInputMethodHints(hints)
Parameters:hintsPySide.QtCore.Qt.InputMethodHints

This property holds What input method specific hints the widget has..

This is only relevant for input widgets. It is used by the input method to retrieve hints as to how the input method should operate. For example, if the Qt.ImhFormattedNumbersOnly flag is set, the input method may change its visual components to reflect that only numbers can be entered.

Note

The flags are only hints, so the particular input method implementation is free to ignore them. If you want to be sure that a certain type of characters are entered, you should also set a PySide.QtGui.QValidator on the widget.

The default value is Qt.ImhNone .

PySide.QtGui.QWidget.setLayout(arg__1)
Parameters:arg__1PySide.QtGui.QLayout

Sets the layout manager for this widget to layout .

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

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

Example:

layout = QVBoxLayout()
layout.addWidget(formWidget)
self.setLayout(layout)

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

The PySide.QtGui.QWidget will take ownership of layout .

See also

PySide.QtGui.QWidget.layout() Layout Management

PySide.QtGui.QWidget.setLayoutDirection(direction)
Parameters:directionPySide.QtCore.Qt.LayoutDirection

This property holds the layout direction for this widget.

By default, this property is set to Qt.LeftToRight .

When the layout direction is set on a widget, it will propagate to the widget’s children, but not to a child that is a window and not to a child for which PySide.QtGui.QWidget.setLayoutDirection() has been explicitly called. Also, child widgets added afterPySide.QtGui.QWidget.setLayoutDirection() has been called for the parent do not inherit the parent’s layout direction.

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

PySide.QtGui.QWidget.setLocale(locale)
Parameters:localePySide.QtCore.QLocale

This property holds the widget’s locale.

As long as no special locale has been set, this is either the parent’s locale or (if this widget is a top level widget), the default locale.

If the widget displays dates or numbers, these should be formatted using the widget’s locale.

See also

PySide.QtCore.QLocale QLocale.setDefault()

PySide.QtGui.QWidget.setMask(arg__1)
Parameters:arg__1PySide.QtGui.QBitmap

Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible. If the region includes pixels outside the PySide.QtGui.QWidget.rect() of the widget, window system controls in that area may or may not be visible, depending on the platform.

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

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

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

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

Masked widgets receive mouse events only on their visible portions.

PySide.QtGui.QWidget.setMask(arg__1)
Parameters:arg__1PySide.QtGui.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 the PySide.QtGui.QWidget.rect() of the widget, window system controls in that area may or may not be visible, depending on the platform.

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

PySide.QtGui.QWidget.setMaximumHeight(maxh)
Parameters:maxhPySide.QtCore.int

This property holds the widget’s maximum height in pixels.

This property corresponds to the height held by the PySide.QtGui.QWidget.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.

PySide.QtGui.QWidget.setMaximumSize(arg__1)
Parameters:arg__1PySide.QtCore.QSize

This property holds the widget’s maximum size in pixels.

The widget cannot be resized to a larger size than the maximum widget size.

By default, this property contains a size in which both width and height have values of 16777215.

Note

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

PySide.QtGui.QWidget.setMaximumSize(maxw, maxh)
Parameters:
  • maxwPySide.QtCore.int
  • maxhPySide.QtCore.int

This is an overloaded function.

This function corresponds to setMaximumSize( PySide.QtCore.QSize (maxw , maxh )). Sets the maximum width to maxw and the maximum height to maxh .

PySide.QtGui.QWidget.setMaximumWidth(maxw)
Parameters:maxwPySide.QtCore.int

This property holds the widget’s maximum width in pixels.

This property corresponds to the width held by the PySide.QtGui.QWidget.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.

PySide.QtGui.QWidget.setMinimumHeight(minh)
Parameters:minhPySide.QtCore.int

This property holds the widget’s minimum height in pixels.

This property corresponds to the height held by the PySide.QtGui.QWidget.minimumSize() property.

By default, this property has a value of 0.

PySide.QtGui.QWidget.setMinimumSize(minw, minh)
Parameters:
  • minwPySide.QtCore.int
  • minhPySide.QtCore.int

This is an overloaded function.

This function corresponds to setMinimumSize( PySide.QtCore.QSize (minw, minh)). Sets the minimum width to minw and the minimum height to minh .

PySide.QtGui.QWidget.setMinimumSize(arg__1)
Parameters:arg__1PySide.QtCore.QSize

This property holds the widget’s minimum size.

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

The minimum size set by this function will override the minimum size defined by PySide.QtGui.QLayout . In order to unset the minimum size, use a value of QSize(0, 0) .

By default, this property contains a size with zero width and height.

PySide.QtGui.QWidget.setMinimumWidth(minw)
Parameters:minwPySide.QtCore.int

This property holds the widget’s minimum width in pixels.

This property corresponds to the width held by the PySide.QtGui.QWidget.minimumSize() property.

By default, this property has a value of 0.

PySide.QtGui.QWidget.setMouseTracking(enable)
Parameters:enablePySide.QtCore.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.

PySide.QtGui.QWidget.setPalette(arg__1)
Parameters:arg__1PySide.QtGui.QPalette

This property holds the widget’s palette.

This property describes the widget’s palette. The palette is used by the widget’s style when rendering standard components, and is available as a means to ensure that custom widgets can maintain consistency with the native platform’s look and feel. It’s common that different platforms, or different styles, have different palettes.

When you assign a new palette to a widget, the color roles from this palette are combined with the widget’s default palette to form the widget’s final palette. The palette entry for the widget’s background role is used to fill the widget’s background (see QWidget.autoFillBackground ), and the foreground role initializes PySide.QtGui.QPainter ‘s pen.

The default depends on the system environment. PySide.QtGui.QApplication maintains a system/theme palette which serves as a default for all widgets. There may also be special palette defaults for certain types of widgets (e.g., on Windows XP and Vista, all classes that derive from PySide.QtGui.QMenuBar have a special default palette). You can also define default palettes for widgets yourself by passing a custom palette and the name of a widget to QApplication.setPalette() . Finally, the style always has the option of polishing the palette as it’s assigned (see QStyle.polish() ).

PySide.QtGui.QWidget propagates explicit palette roles from parent to child. If you assign a brush or color to a specific role on a palette and assign that palette to a widget, that role will propagate to all the widget’s children, overriding any system defaults for that role. Note that palettes by default don’t propagate to windows (see PySide.QtGui.QWidget.isWindow() ) unless the Qt.WA_WindowPropagation attribute is enabled.

PySide.QtGui.QWidget ‘s palette propagation is similar to its font propagation.

The current style, which is used to render the content of all standard Qt widgets, is free to choose colors and brushes from the widget palette, or in some cases, to ignore the palette (partially, or completely). In particular, certain styles like GTK style, Mac style, Windows XP, and Vista style, depend on third party APIs to render the content of widgets, and these styles typically do not follow the palette. Because of this, assigning roles to a widget’s palette is not guaranteed to change the appearance of the widget. Instead, you may choose to apply a PySide.QtGui.QWidget.styleSheet() . You can refer to our Knowledge Base article here for more information.

Warning

Do not use this function in conjunction with Qt Style Sheets . When using style sheets, the palette of a widget can be customized using the “color”, “background-color”, “selection-color”, “selection-background-color” and “alternate-background-color”.

PySide.QtGui.QWidget.setParent(parent, f)
Parameters:
PySide.QtGui.QWidget.setParent(parent)
Parameters:parentPySide.QtGui.QWidget

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, PySide.QtGui.QWidget.setParent() calls PySide.QtGui.QWidget.clearFocus() for that widget.

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

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

Note

The widget becomes invisible as part of changing its parent, even if it was previously visible. You must call PySide.QtGui.QWidget.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 PySide.QtGui.QStackedWidget .

PySide.QtGui.QWidget.setShortcutAutoRepeat(id[, enable=true])
Parameters:
  • idPySide.QtCore.int
  • enablePySide.QtCore.bool

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

PySide.QtGui.QWidget.setShortcutEnabled(id[, enable=true])
Parameters:
  • idPySide.QtCore.int
  • enablePySide.QtCore.bool

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

Warning

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

PySide.QtGui.QWidget.setSizeIncrement(w, h)
Parameters:
  • wPySide.QtCore.int
  • hPySide.QtCore.int

This is an overloaded function.

Sets the x (width) size increment to w and the y (height) size increment to h .

PySide.QtGui.QWidget.setSizeIncrement(arg__1)
Parameters:arg__1PySide.QtCore.QSize

This property holds the size increment of the widget.

When the user resizes the window, the size will move in steps of PySide.QtGui.QWidget.sizeIncrement() . PySide.QtGui.QWidget.width() pixels horizontally and PySide.QtGui.QWidget.sizeIncrement() . PySide.QtGui.QWidget.height() pixels vertically, with PySide.QtGui.QWidget.baseSize() as the basis. Preferred widget sizes are for non-negative integers i and j :

width = widget.baseSize().width() + i * widget.sizeIncrement().width()
height = widget.baseSize().height() + j * widget.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.

PySide.QtGui.QWidget.setSizePolicy(arg__1)
Parameters:arg__1PySide.QtGui.QSizePolicy

This property holds the default layout behavior of the widget.

If there is a PySide.QtGui.QLayout that manages this widget’s children, the size policy specified by that layout is used. If there is no such PySide.QtGui.QLayout , the result of this function is used.

The default policy is Preferred/Preferred, which means that the widget can be freely resized, but prefers to be the size PySide.QtGui.QWidget.sizeHint() returns. Button-like widgets set the size policy to specify that they may stretch horizontally, but are fixed vertically. The same applies to lineedit controls (such as PySide.QtGui.QLineEdit , PySide.QtGui.QSpinBox or an editable PySide.QtGui.QComboBox ) and other horizontally orientated widgets (such as PySide.QtGui.QProgressBar ). PySide.QtGui.QToolButton ‘s are normally square, so they allow growth in both directions. Widgets that support different directions (such as PySide.QtGui.QSlider , PySide.QtGui.QScrollBar or QHeader ) specify stretching in the respective direction only. Widgets that can provide scroll bars (usually subclasses of PySide.QtGui.QScrollArea ) tend to specify that they can use additional space, and that they can make do with less than PySide.QtGui.QWidget.sizeHint() .

PySide.QtGui.QWidget.setSizePolicy(horizontal, vertical)
Parameters:
PySide.QtGui.QWidget.setStatusTip(arg__1)
Parameters:arg__1 – unicode

This property holds the widget’s status tip.

By default, this property contains an empty string.

PySide.QtGui.QWidget.setStyle(arg__1)
Parameters:arg__1PySide.QtGui.QStyle

Sets the widget’s GUI style to style . The ownership of the style object is not transferred.

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

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

Warning

This function is particularly useful for demonstration purposes, where you want to show Qt’s styling capabilities. Real applications should avoid it and use one consistent GUI style instead.

Warning

Qt style sheets are currently not supported for custom PySide.QtGui.QStyle subclasses. We plan to address this in some future release.

PySide.QtGui.QWidget.setStyleSheet(styleSheet)
Parameters:styleSheet – unicode

This property holds the widget’s style sheet.

The style sheet contains a textual description of customizations to the widget’s style, as described in the Qt Style Sheets document.

Since Qt 4.5, Qt style sheets fully supports Mac OS X.

Warning

Qt style sheets are currently not supported for custom PySide.QtGui.QStyle subclasses. We plan to address this in some future release.

static PySide.QtGui.QWidget.setTabOrder(arg__1, arg__2)
Parameters:

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

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

widget.setTabOrder(a, b) # a to b
widget.setTabOrder(b, c) # a to b to c
widge.tsetTabOrder(c, d) # a to b to c to d

not like this:

# WRONG
widget.setTabOrder(c, d) # c to d
widget.setTabOrder(a, b) # a to b AND c to d
widget.setTabOrder(b, c) # a to b to c, but not c to d

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

PySide.QtGui.QWidget.setToolTip(arg__1)
Parameters:arg__1 – unicode

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 PySide.QtGui.QWidget.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.

PySide.QtGui.QWidget.setUpdatesEnabled(enable)
Parameters:enablePySide.QtCore.bool

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 PySide.QtGui.QWidget.update() and PySide.QtGui.QWidget.repaint() has no effect if updates are disabled.

By default, this property is true.

PySide.QtGui.QWidget.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:

widget.setUpdatesEnabled(False)
widget.bigVisualChanges()
widget.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 PySide.QtGui.QWidget.update() on the widget.

PySide.QtGui.QWidget.setVisible(visible)
Parameters:visiblePySide.QtCore.bool

This property holds whether the widget is visible.

Calling setVisible(true) or PySide.QtGui.QWidget.show() sets the widget to visible status if all its parent widgets up to the window are visible. If an ancestor is not visible, the widget won’t become visible until all its ancestors are shown. If its size or position has changed, Qt guarantees that a widget gets move and resize events just before it is shown. If the widget has not been resized yet, Qt will adjust the widget’s size to a useful default using PySide.QtGui.QWidget.adjustSize() .

Calling setVisible(false) or PySide.QtGui.QWidget.hide() hides a widget explicitly. An explicitly hidden widget will never become visible, even if all its ancestors become visible, unless you show it.

A widget receives show and hide events when its visibility status changes. Between a hide and a show event, there is no need to waste CPU cycles preparing or displaying information to the user. A video application, for example, might simply stop generating new frames.

A widget that happens to be obscured by other windows on the screen is considered to be visible. The same applies to iconified windows and windows that exist on another virtual desktop (on platforms that support this concept). A widget receives spontaneous show and hide events when its mapping status is changed by the window system, e.g. a spontaneous hide event when the user minimizes the window, and a spontaneous show event when the window is restored again.

You almost never have to reimplement the PySide.QtGui.QWidget.setVisible() function. If you need to change some settings before a widget is shown, use PySide.QtGui.QWidget.showEvent() instead. If you need to do some delayed initialization use the Polish event delivered to the PySide.QtGui.QWidget.event() function.

PySide.QtGui.QWidget.setWhatsThis(arg__1)
Parameters:arg__1 – unicode

This property holds the widget’s What’s This help text..

By default, this property contains an empty string.

See also

PySide.QtGui.QWhatsThis QWidget.toolTip QWidget.statusTip

PySide.QtGui.QWidget.setWindowFilePath(filePath)
Parameters:filePath – unicode

This property holds the file path associated with a widget.

This property only makes sense for windows. It associates a file path with a window. If you set the file path, but have not set the window title, Qt sets the window title to contain a string created using the following components.

On Mac OS X:

  • The file name of the specified path, obtained using QFileInfo.fileName() .

On Windows and X11:

  • The file name of the specified path, obtained using QFileInfo.fileName() .
  • An optional * character, if the windowModified() property is set.
  • The 0x2014 unicode character, padded either side by spaces.
  • The application name, obtained from the application’s PySide.QtCore.QCoreApplication.applicationName() property.

If the window title is set at any point, then the window title takes precedence and will be shown instead of the file path string.

Additionally, on Mac OS X, this has an added benefit that it sets the proxy icon for the window, assuming that the file path exists.

If no file path is set, this property contains an empty string.

By default, this property contains an empty string.

PySide.QtGui.QWidget.setWindowFlags(type)
Parameters:typePySide.QtCore.Qt.WindowFlags
PySide.QtGui.QWidget.setWindowIcon(icon)
Parameters:iconPySide.QtGui.QIcon

This property holds the widget’s icon.

This property only makes sense for windows. If no icon has been set, PySide.QtGui.QWidget.windowIcon() returns the application icon ( QApplication.windowIcon() ).

PySide.QtGui.QWidget.setWindowIconText(arg__1)
Parameters:arg__1 – unicode

This property holds the widget’s icon text.

This property only makes sense for windows. If no icon text has been set, this functions returns an empty string.

PySide.QtGui.QWidget.setWindowModality(windowModality)
Parameters:windowModalityPySide.QtCore.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 PySide.QtGui.QWidget.hide() the widget first, then PySide.QtGui.QWidget.show() it again.

By default, this property is Qt.NonModal .

PySide.QtGui.QWidget.setWindowModified(arg__1)
Parameters:arg__1PySide.QtCore.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 Mac OS X the close button will have a modified look; on other platforms, the window title will have an ‘*’ (asterisk).

The window title must contain a “[*]” placeholder, which indicates where the ‘*’ should appear. Normally, it should appear right after the file name (e.g., “document1.txt[*] - Text Editor”). If the window isn’t modified, the placeholder is simply removed.

Note that if a widget is set as modified, all its ancestors will also be set as modified. However, if you call setWindowModified(false) on a widget, this will not propagate to its parent because other children of the parent might have been modified.

See also

PySide.QtGui.QWidget.windowTitle() Application Example SDI Example MDI Example

PySide.QtGui.QWidget.setWindowOpacity(level)
Parameters:levelPySide.QtCore.qreal
PySide.QtGui.QWidget.setWindowRole(arg__1)
Parameters:arg__1 – unicode

Sets the window’s role to role . This only makes sense for windows on X11.

PySide.QtGui.QWidget.setWindowState(state)
Parameters:statePySide.QtCore.Qt.WindowStates
PySide.QtGui.QWidget.setWindowTitle(arg__1)
Parameters:arg__1 – unicode

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 PySide.QtGui.QWidget.windowFilePath() . If neither of these is set, then the title is an empty string.

If you use the windowModified() mechanism, the window title must contain a “[*]” placeholder, which indicates where the ‘*’ should appear. Normally, it should appear right after the file name (e.g., “document1.txt[*] - Text Editor”). If the windowModified() property is false (the default), the placeholder is simply removed.

PySide.QtGui.QWidget.show()

Shows the widget and its child widgets. This function is equivalent to setVisible(true).

PySide.QtGui.QWidget.showEvent(event)
Parameters:eventPySide.QtGui.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 PySide.QtGui.QWidget.isVisible() .

See also

visible() PySide.QtGui.QWidget.event() PySide.QtGui.QShowEvent

PySide.QtGui.QWidget.showFullScreen()

Shows the widget in full-screen mode.

Calling this function only affects windows .

To return from full-screen mode, call PySide.QtGui.QWidget.showNormal() .

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

PySide.QtGui.QWidget.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.

PySide.QtGui.QWidget.showMinimized()

Shows the widget minimized, as an icon.

Calling this function only affects windows .

PySide.QtGui.QWidget.showNormal()

Restores the widget after it has been maximized or minimized.

Calling this function only affects windows .

PySide.QtGui.QWidget.size()
Return type:PySide.QtCore.QSize

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 ( PySide.QtGui.QWidget.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 PySide.QtGui.QWidget.minimumSize() and PySide.QtGui.QWidget.maximumSize() .

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

Note

Setting the size to QSize(0, 0) will cause the widget to not appear on screen. This also applies to windows.

PySide.QtGui.QWidget.sizeHint()
Return type:PySide.QtCore.QSize

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 PySide.QtGui.QWidget.sizeHint() returns an invalid size if there is no layout for this widget, and returns the layout’s preferred size otherwise.

PySide.QtGui.QWidget.sizeIncrement()
Return type:PySide.QtCore.QSize

This property holds the size increment of the widget.

When the user resizes the window, the size will move in steps of PySide.QtGui.QWidget.sizeIncrement() . PySide.QtGui.QWidget.width() pixels horizontally and PySide.QtGui.QWidget.sizeIncrement() . PySide.QtGui.QWidget.height() pixels vertically, with PySide.QtGui.QWidget.baseSize() as the basis. Preferred widget sizes are for non-negative integers i and j :

width = widget.baseSize().width() + i * widget.sizeIncrement().width()
height = widget.baseSize().height() + j * widget.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.

PySide.QtGui.QWidget.sizePolicy()
Return type:PySide.QtGui.QSizePolicy

This property holds the default layout behavior of the widget.

If there is a PySide.QtGui.QLayout that manages this widget’s children, the size policy specified by that layout is used. If there is no such PySide.QtGui.QLayout , the result of this function is used.

The default policy is Preferred/Preferred, which means that the widget can be freely resized, but prefers to be the size PySide.QtGui.QWidget.sizeHint() returns. Button-like widgets set the size policy to specify that they may stretch horizontally, but are fixed vertically. The same applies to lineedit controls (such as PySide.QtGui.QLineEdit , PySide.QtGui.QSpinBox or an editable PySide.QtGui.QComboBox ) and other horizontally orientated widgets (such as PySide.QtGui.QProgressBar ). PySide.QtGui.QToolButton ‘s are normally square, so they allow growth in both directions. Widgets that support different directions (such as PySide.QtGui.QSlider , PySide.QtGui.QScrollBar or QHeader ) specify stretching in the respective direction only. Widgets that can provide scroll bars (usually subclasses of PySide.QtGui.QScrollArea ) tend to specify that they can use additional space, and that they can make do with less than PySide.QtGui.QWidget.sizeHint() .

PySide.QtGui.QWidget.stackUnder(arg__1)
Parameters:arg__1PySide.QtGui.QWidget

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() PySide.QtGui.QWidget.lower()

PySide.QtGui.QWidget.statusTip()
Return type:unicode

This property holds the widget’s status tip.

By default, this property contains an empty string.

PySide.QtGui.QWidget.style()
Return type:PySide.QtGui.QStyle
PySide.QtGui.QWidget.styleSheet()
Return type:unicode

This property holds the widget’s style sheet.

The style sheet contains a textual description of customizations to the widget’s style, as described in the Qt Style Sheets document.

Since Qt 4.5, Qt style sheets fully supports Mac OS X.

Warning

Qt style sheets are currently not supported for custom PySide.QtGui.QStyle subclasses. We plan to address this in some future release.

PySide.QtGui.QWidget.tabletEvent(event)
Parameters:eventPySide.QtGui.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.

See also

QTabletEvent.ignore() QTabletEvent.accept() PySide.QtGui.QWidget.event() PySide.QtGui.QTabletEvent

PySide.QtGui.QWidget.takeLayout()
Return type:PySide.QtGui.QLayout
PySide.QtGui.QWidget.testAttribute(arg__1)
Parameters:arg__1PySide.QtCore.Qt.WidgetAttribute
Return type:PySide.QtCore.bool
PySide.QtGui.QWidget.testAttribute_helper(arg__1)
Parameters:arg__1PySide.QtCore.Qt.WidgetAttribute
Return type:PySide.QtCore.bool
PySide.QtGui.QWidget.toolTip()
Return type:unicode

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 PySide.QtGui.QWidget.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.

PySide.QtGui.QWidget.underMouse()
Return type:PySide.QtCore.bool

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

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

PySide.QtGui.QWidget.ungrabGesture(type)
Parameters:typePySide.QtCore.Qt.GestureType
PySide.QtGui.QWidget.unsetCursor()

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:

widget.setCursor(Qt.IBeamCursor)

If no cursor has been set, or after a call to PySide.QtGui.QWidget.unsetCursor() , the parent’s cursor is used.

By default, this property contains a cursor with the Qt.ArrowCursor shape.

Some underlying window implementations will reset the cursor if it leaves a widget even if the mouse is grabbed. If you want to have a cursor set for all widgets, even when outside the window, consider QApplication.setOverrideCursor() .

PySide.QtGui.QWidget.unsetLayoutDirection()

This property holds the layout direction for this widget.

By default, this property is set to Qt.LeftToRight .

When the layout direction is set on a widget, it will propagate to the widget’s children, but not to a child that is a window and not to a child for which PySide.QtGui.QWidget.setLayoutDirection() has been explicitly called. Also, child widgets added afterPySide.QtGui.QWidget.setLayoutDirection() has been called for the parent do not inherit the parent’s layout direction.

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

PySide.QtGui.QWidget.unsetLocale()

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

PySide.QtCore.QLocale QLocale.setDefault()

PySide.QtGui.QWidget.update(x, y, w, h)
Parameters:
  • xPySide.QtCore.int
  • yPySide.QtCore.int
  • wPySide.QtCore.int
  • hPySide.QtCore.int

This is an overloaded function.

This version updates a rectangle (x , y , w , h ) inside the widget.

PySide.QtGui.QWidget.update(arg__1)
Parameters:arg__1PySide.QtGui.QRegion

This is an overloaded function.

This version repaints a region rgn inside the widget.

PySide.QtGui.QWidget.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 PySide.QtGui.QWidget.repaint() does.

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

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

PySide.QtGui.QWidget.update(arg__1)
Parameters:arg__1PySide.QtCore.QRect

This is an overloaded function.

This version updates a rectangle rect inside the widget.

PySide.QtGui.QWidget.updateGeometry()

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

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

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

PySide.QtGui.QWidget.updateMicroFocus()

Updates the widget’s micro focus.

PySide.QtGui.QWidget.updatesEnabled()
Return type:PySide.QtCore.bool

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 PySide.QtGui.QWidget.update() and PySide.QtGui.QWidget.repaint() has no effect if updates are disabled.

By default, this property is true.

PySide.QtGui.QWidget.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:

widget.setUpdatesEnabled(False)
widget.bigVisualChanges()
widget.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 PySide.QtGui.QWidget.update() on the widget.

PySide.QtGui.QWidget.visibleRegion()
Return type:PySide.QtGui.QRegion

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 PySide.QtGui.QWidget.repaint() function calls this function if necessary, so in general you do not need to call it.

PySide.QtGui.QWidget.whatsThis()
Return type:unicode

This property holds the widget’s What’s This help text..

By default, this property contains an empty string.

See also

PySide.QtGui.QWhatsThis QWidget.toolTip QWidget.statusTip

PySide.QtGui.QWidget.wheelEvent(event)
Parameters:eventPySide.QtGui.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

QWheelEvent.ignore() QWheelEvent.accept() PySide.QtGui.QWidget.event() PySide.QtGui.QWheelEvent

PySide.QtGui.QWidget.winId()
Return type:long

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.

On X11 the type returned is long, on other platforms it’s a PyCObject.

This value may change at run-time. An event with type PySide.QtCore.QEvent.WinIdChange will be sent to the widget following a change in window system identifier.

PySide.QtGui.QWidget.window()
Return type:PySide.QtGui.QWidget

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")
PySide.QtGui.QWidget.windowFilePath()
Return type:unicode

This property holds the file path associated with a widget.

This property only makes sense for windows. It associates a file path with a window. If you set the file path, but have not set the window title, Qt sets the window title to contain a string created using the following components.

On Mac OS X:

  • The file name of the specified path, obtained using QFileInfo.fileName() .

On Windows and X11:

  • The file name of the specified path, obtained using QFileInfo.fileName() .
  • An optional * character, if the windowModified() property is set.
  • The 0x2014 unicode character, padded either side by spaces.
  • The application name, obtained from the application’s PySide.QtCore.QCoreApplication.applicationName() property.

If the window title is set at any point, then the window title takes precedence and will be shown instead of the file path string.

Additionally, on Mac OS X, this has an added benefit that it sets the proxy icon for the window, assuming that the file path exists.

If no file path is set, this property contains an empty string.

By default, this property contains an empty string.

PySide.QtGui.QWidget.windowFlags()
Return type:PySide.QtCore.Qt.WindowFlags
PySide.QtGui.QWidget.windowIcon()
Return type:PySide.QtGui.QIcon

This property holds the widget’s icon.

This property only makes sense for windows. If no icon has been set, PySide.QtGui.QWidget.windowIcon() returns the application icon ( QApplication.windowIcon() ).

PySide.QtGui.QWidget.windowIconText()
Return type:unicode

This property holds the widget’s icon text.

This property only makes sense for windows. If no icon text has been set, this functions returns an empty string.

PySide.QtGui.QWidget.windowModality()
Return type:PySide.QtCore.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 PySide.QtGui.QWidget.hide() the widget first, then PySide.QtGui.QWidget.show() it again.

By default, this property is Qt.NonModal .

PySide.QtGui.QWidget.windowOpacity()
Return type:PySide.QtCore.qreal
PySide.QtGui.QWidget.windowRole()
Return type:unicode

Returns the window’s role, or an empty string.

PySide.QtGui.QWidget.windowState()
Return type:PySide.QtCore.Qt.WindowStates

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

Qt.WindowState PySide.QtGui.QWidget.setWindowState()

PySide.QtGui.QWidget.windowTitle()
Return type:unicode

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 PySide.QtGui.QWidget.windowFilePath() . If neither of these is set, then the title is an empty string.

If you use the windowModified() mechanism, the window title must contain a “[*]” placeholder, which indicates where the ‘*’ should appear. Normally, it should appear right after the file name (e.g., “document1.txt[*] - Text Editor”). If the windowModified() property is false (the default), the placeholder is simply removed.

PySide.QtGui.QWidget.windowType()
Return type:PySide.QtCore.Qt.WindowType

Returns the window type of this widget. This is identical to PySide.QtGui.QWidget.windowFlags() & Qt.WindowType_Mask .

PySide.QtGui.QWidget.x()
Return type:PySide.QtCore.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.

PySide.QtGui.QWidget.x11Info()
Return type:PySide.QtGui.QX11Info

Returns information about the configuration of the X display used to display the widget.

Warning

This function is only available on X11.

PySide.QtGui.QWidget.x11PictureHandle()
Return type:PySide.QtCore.Qt::HANDLE

Returns the X11 Picture handle of the widget for XRender support. Use of this function is not portable. This function will return 0 if XRender support is not compiled into Qt, if the XRender extension is not supported on the X11 display, or if the handle could not be created.

PySide.QtGui.QWidget.y()
Return type:PySide.QtCore.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.