QGraphicsWidget露
The QGraphicsWidget class is the base class for all widget items in a
QGraphicsScene. More鈥

Inherited by: QChart, QLegend, QPolarChart, QGraphicsProxyWidget
Synopsis露
Functions露
def
actions()def
addAction(action)def
addActions(actions)def
adjustSize()def
autoFillBackground()def
focusPolicy()def
focusWidget()def
font()def
getWindowFrameMargins()def
grabShortcut(sequence[, context=Qt.WindowShortcut])def
insertAction(before, action)def
insertActions(before, actions)def
isActiveWindow()def
layout()def
layoutDirection()def
palette()def
rect()def
releaseShortcut(id)def
removeAction(action)def
resize(size)def
resize(w, h)def
setAttribute(attribute[, on=true])def
setAutoFillBackground(enabled)def
setContentsMargins(left, top, right, bottom)def
setContentsMargins(margins)def
setFocusPolicy(policy)def
setFont(font)def
setGeometry(x, y, w, h)def
setLayout(layout)def
setLayoutDirection(direction)def
setPalette(palette)def
setShortcutAutoRepeat(id[, enabled=true])def
setShortcutEnabled(id[, enabled=true])def
setStyle(style)def
setWindowFlags(wFlags)def
setWindowFrameMargins(left, top, right, bottom)def
setWindowFrameMargins(margins)def
setWindowTitle(title)def
size()def
style()def
testAttribute(attribute)def
unsetLayoutDirection()def
unsetWindowFrameMargins()def
windowFlags()def
windowFrameGeometry()def
windowFrameRect()def
windowTitle()def
windowType()
Virtual functions露
def
changeEvent(event)def
closeEvent(event)def
focusNextPrevChild(next)def
grabKeyboardEvent(event)def
grabMouseEvent(event)def
hideEvent(event)def
initStyleOption(option)def
moveEvent(event)def
paintWindowFrame(painter, option[, widget=None])def
polishEvent()def
propertyChange(propertyName, value)def
resizeEvent(event)def
showEvent(event)def
ungrabKeyboardEvent(event)def
ungrabMouseEvent(event)def
windowFrameEvent(e)def
windowFrameSectionAt(pos)
Slots露
def
close()
Signals露
def
geometryChanged()def
layoutChanged()
Static functions露
def
setTabOrder(first, second)
Detailed Description露
QGraphicsWidget is an extended base item that provides extra functionality over
QGraphicsItem. It is similar toQWidgetin many ways:
Has a defined
geometry().Supports layouts with
setLayout()andlayout().Supports shortcuts and actions with
grabShortcut()andinsertAction()Unlike
QGraphicsItem, QGraphicsWidget is not an abstract class; you can create instances of a QGraphicsWidget without having to subclass it. This approach is useful for widgets that only serve the purpose of organizing child widgets into a layout.QGraphicsWidget can be used as a base item for your own custom item if you require advanced input focus handling, e.g., tab focus and activation, or layouts.
Since QGraphicsWidget resembles
QWidgetand has similar API, it is easier to port a widget fromQWidgetto QGraphicsWidget , instead ofQGraphicsItem.Note
QWidget-based widgets can be directly embedded into aQGraphicsSceneusingQGraphicsProxyWidget.Noticeable differences between QGraphicsWidget and
QWidgetare:
Coordinates and geometry are defined with qreals (doubles or floats, depending on the platform).
QWidgetuses integer geometry (QPoint,QRect).The widget is already visible by default; you do not have to call
show()to display the widget.
QWidgetis hidden by default until you callshow().A subset of widget attributes are supported.
All widget attributes are supported.
A top-level item鈥檚 style defaults to
styleA top-level widget鈥檚 style defaults to
styleGraphics View provides a custom drag and drop framework, different from
QWidget.Standard drag and drop framework.
Widget items do not support modality.
Full modality support.
QGraphicsWidget supports a subset of Qt鈥檚 widget attributes, (
WidgetAttribute), as shown in the table below. Any attributes not listed in this table are unsupported, or otherwise unused.
Widget Attribute
Usage
WA_SetLayoutDirectionSet by
setLayoutDirection(), cleared byunsetLayoutDirection(). You can test this attribute to check if the widget has been explicitly assigned alayoutDirection. If the attribute is not set, thelayoutDirection()is inherited.
WA_RightToLeftToggled by
setLayoutDirection(). Inherited from the parent/scene. If set, the widget鈥檚 layout will order horizontally arranged widgets from right to left.
WA_SetStyleSet and cleared by
setStyle(). If this attribute is set, the widget has been explicitly assigned a style. If it is unset, the widget will use the scene鈥檚 or the application鈥檚 style.
WA_ResizedSet by
setGeometry()andresize().
WA_SetPaletteSet by
setPalette().
WA_SetFontSet by
setFont().
WA_WindowPropagationEnables propagation to window widgets.
Although QGraphicsWidget inherits from both
QObjectandQGraphicsItem, you should use the functions provided byQGraphicsItem, notQObject, to manage the relationships between parent and child items. These functions control the stacking order of items as well as their ownership.Note
The
parent()should always returnNonefor QGraphicsWidgets, but this policy is not strictly defined.
- class PySide2.QtWidgets.QGraphicsWidget([parent=None[, wFlags=Qt.WindowFlags()]])露
- param parent:
- param wFlags:
WindowFlags
Constructs a QGraphicsWidget instance. The optional
parentargument is passed toQGraphicsItem鈥榮 constructor. The optionalwFlagsargument specifies the widget鈥檚 window flags (e.g., whether the widget should be a window, a tool, a popup, etc).
- PySide2.QtWidgets.QGraphicsWidget.actions()露
- Return type:
Returns the (possibly empty) list of this widget鈥檚 actions.
See also
insertAction()removeAction()actions()associatedWidgets()associatedGraphicsWidgets()
- PySide2.QtWidgets.QGraphicsWidget.addAction(action)露
- Parameters:
action 鈥
PySide2.QtWidgets.QAction
Appends the action
actionto this widget鈥檚 list of actions.All QGraphicsWidgets have a list of
QActions, however they can be represented graphically in many different ways. The default use of theQActionlist (as returned byactions()) is to create a contextQMenu.A QGraphicsWidget 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.
See also
- PySide2.QtWidgets.QGraphicsWidget.addActions(actions)露
- Parameters:
actions 鈥
Appends the actions
actionsto this widget鈥檚 list of actions.See also
- PySide2.QtWidgets.QGraphicsWidget.adjustSize()露
Adjusts the size of the widget to its effective preferred size hint.
This function is called implicitly when the item is shown for the first time.
See also
effectiveSizeHint()MinimumSize
- PySide2.QtWidgets.QGraphicsWidget.autoFillBackground()露
- Return type:
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()method. The color used is defined by theWindowcolor role from the widget鈥檚palette.In addition, Windows are always filled with
Window, unless the WA_OpaquePaintEvent or WA_NoSystemBackground attributes are set.By default, this property is
false.See also
WA_OpaquePaintEventWA_NoSystemBackground
- PySide2.QtWidgets.QGraphicsWidget.changeEvent(event)露
- Parameters:
event 鈥
PySide2.QtCore.QEvent
This event handler can be reimplemented to handle state changes.
The state being changed in this event can be retrieved through
event.Change events include:
ActivationChange,EnabledChange,FontChange,StyleChange,PaletteChange,ParentChange,LayoutDirectionChange, andContentsRectChange.
- PySide2.QtWidgets.QGraphicsWidget.close()露
- Return type:
bool
Call this function to close the widget.
Returns
trueif the widget was closed; otherwise returnsfalse. This slot will first send aQCloseEventto the widget, which may or may not accept the event. If the event was ignored, nothing happens. If the event was accepted, it willhide()the widget.If the widget has the
WA_DeleteOnCloseattribute set it will be deleted.
- PySide2.QtWidgets.QGraphicsWidget.closeEvent(event)露
- Parameters:
event 鈥
PySide2.QtGui.QCloseEvent
This event handler, for
event, can be reimplemented in a subclass to receive widget close events. The default implementation accepts the event.See also
close()QCloseEvent
- PySide2.QtWidgets.QGraphicsWidget.focusNextPrevChild(next)露
- Parameters:
next 鈥 bool
- Return type:
bool
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns
trueif it can find a new widget; returnsfalseotherwise. Ifnextis true, this function searches forward; ifnextis false, it searches backward.Sometimes, you will want to reimplement this function to provide special focus handling for your widget and its subwidgets. For example, a web browser might reimplement it to move its current active link forward or backward, and call the base implementation only when it reaches the last or first link on the page.
Child widgets call 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 gain control of focus traversal for all child widgets.
See also
- PySide2.QtWidgets.QGraphicsWidget.focusPolicy()露
- Return type:
This property holds the way the widget accepts keyboard focus.
The focus policy is
TabFocusif the widget accepts keyboard focus by tabbing,ClickFocusif the widget accepts focus by clicking,StrongFocusif it accepts both, andNoFocus(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鈥檚 constructor. For instance, the
QLineEditconstructor calls (StrongFocus).If you enable a focus policy (i.e., not
NoFocus), QGraphicsWidget will automatically enable theItemIsFocusableflag. SettingNoFocuson a widget will clear theItemIsFocusableflag. If the widget currently has keyboard focus, the widget will automatically lose focus.See also
focusInEvent()focusOutEvent()keyPressEvent()keyReleaseEvent()enabled
- PySide2.QtWidgets.QGraphicsWidget.focusWidget()露
- Return type:
If this widget, a child or descendant of this widget currently has input focus, this function will return a pointer to that widget. If no descendant widget has input focus,
Noneis returned.See also
- PySide2.QtWidgets.QGraphicsWidget.font()露
- Return type:
This property holds the widgets鈥 font.
This property provides the widget鈥檚 font.
QFontconsists of font properties that have been explicitly defined and properties implicitly inherited from the widget鈥檚 parent. Hence, can return a different font compared to the one set with . This scheme allows you to define single entries in a font without affecting the font鈥檚 inherited entries.When a widget鈥檚 font changes, it resolves its entries against its parent widget. If the widget does not have a parent widget, it resolves its entries against the scene. The widget then sends itself a
FontChangeevent and notifies all its descendants so that they can resolve their fonts as well.By default, this property contains the application鈥檚 default font.
- PySide2.QtWidgets.QGraphicsWidget.geometryChanged()露
- PySide2.QtWidgets.QGraphicsWidget.getWindowFrameMargins()露
Gets the widget鈥檚 window frame margins. The margins are stored in
left,top,rightandbottomas pointers to qreals. Each argument can be omitted by passingNone.See also
- PySide2.QtWidgets.QGraphicsWidget.grabKeyboardEvent(event)露
- Parameters:
event 鈥
PySide2.QtCore.QEvent
This event handler, for
event, can be reimplemented in a subclass to receive notifications forGrabKeyboardevents.See also
grabKeyboard()grabMouse()
- PySide2.QtWidgets.QGraphicsWidget.grabMouseEvent(event)露
- Parameters:
event 鈥
PySide2.QtCore.QEvent
This event handler, for
event, can be reimplemented in a subclass to receive notifications forGrabMouseevents.See also
grabMouse()grabKeyboard()
- PySide2.QtWidgets.QGraphicsWidget.grabShortcut(sequence[, context=Qt.WindowShortcut])露
- Parameters:
sequence 鈥
PySide2.QtGui.QKeySequencecontext 鈥
ShortcutContext
- Return type:
int
Adds a shortcut to Qt鈥檚 shortcut system that watches for the given key
sequencein the givencontext. If thecontextisApplicationShortcut, the shortcut applies to the application as a whole. Otherwise, it is either local to this widget,WidgetShortcut, or to the window itself,WindowShortcut. For widgets that are not part of a window (i.e., top-level widgets and their children),WindowShortcutshortcuts apply to the scene.If the same key
sequencehas been grabbed by several widgets, when the keysequenceoccurs aShortcutevent is sent to all the widgets to which it applies in a non-deterministic order, but with the ``ambiguous鈥欌 flag set to true.Warning
You should not normally need to use this function; instead create
QActions with the shortcut key sequences you require (if you also want equivalent menu options and toolbar buttons), or createQShortcuts if you just need key sequences. BothQActionandQShortcuthandle all the event filtering for you, and provide signals which are triggered when the user triggers the key sequence, so are much easier to use than this low-level function.
- PySide2.QtWidgets.QGraphicsWidget.hideEvent(event)露
- Parameters:
event 鈥
PySide2.QtGui.QHideEvent
This event handler, for
Hideevents, is delivered after the widget has been hidden, for example,setVisible(false) has been called for the widget or one of its ancestors when the widget was previously shown.You can reimplement this event handler to detect when your widget is hidden. Calling
accept()orignore()oneventhas no effect.See also
showEvent()hideEvent()ItemVisibleChange
- PySide2.QtWidgets.QGraphicsWidget.initStyleOption(option)露
- Parameters:
option 鈥
PySide2.QtWidgets.QStyleOption
Populates a style option object for this widget based on its current state, and stores the output in
option. The default implementation populatesoptionwith the following properties.Style Option Property
Value
state &
State_EnabledCorresponds to
isEnabled().state &
State_HasFocusCorresponds to
hasFocus().state &
State_MouseOverCorresponds to
isUnderMouse().direction
Corresponds to
layoutDirection().rect
Corresponds to
rect().toRect().palette
Corresponds to
palette().fontMetrics
Corresponds to
QFontMetrics(font()).Subclasses of QGraphicsWidget should call the base implementation, and then test the type of
optionusingqstyleoption_cast<>() or testTypebefore storing widget-specific options.For example:
class MyGroupBoxWidget (QStyleOptionGroupBox): # ... def initStyleOption(option): QGraphicsWidget.initStyleOption(self, option) if isinstance(option, QStyleOptionGroupBox): # Add group box specific state. box.flat = isFlat() # ...
See also
- PySide2.QtWidgets.QGraphicsWidget.insertAction(before, action)露
- Parameters:
before 鈥
PySide2.QtWidgets.QActionaction 鈥
PySide2.QtWidgets.QAction
Inserts the action
actionto this widget鈥檚 list of actions, before the actionbefore. It appends the action ifbeforeisNoneorbeforeis not a valid action for this widget.A QGraphicsWidget should only have one of each action.
- PySide2.QtWidgets.QGraphicsWidget.insertActions(before, actions)露
- Parameters:
before 鈥
PySide2.QtWidgets.QActionactions 鈥
Inserts the actions
actionsto this widget鈥檚 list of actions, before the actionbefore. It appends the action ifbeforeisNoneorbeforeis not a valid action for this widget.A QGraphicsWidget can have at most one of each action.
See also
- PySide2.QtWidgets.QGraphicsWidget.isActiveWindow()露
- Return type:
bool
Returns
trueif this widget鈥檚 window is in the active window, or if the widget does not have a window but is in an active scene (i.e., a scene that currently has focus).The active window is the window that either contains a child widget that currently has input focus, or that itself has input focus.
See also
activeWindow()setActiveWindow()isActive()
- PySide2.QtWidgets.QGraphicsWidget.layout()露
- Return type:
This property holds The layout of the widget.
Any existing layout manager is deleted before the new layout is assigned. If
layoutisNone, the widget is left without a layout. Existing subwidgets鈥 geometries will remain unaffected.QGraphicsWidget takes ownership of
layout.All widgets that are currently managed by
layoutor all of its sublayouts, are automatically reparented to this item. The layout is then invalidated, and the child widget geometries are adjusted according to this item鈥檚geometry()and contentsMargins(). Children who are not explicitly managed bylayoutremain unaffected by the layout after it has been assigned to this widget.If no layout is currently managing this widget,
layout()will returnNone.
- PySide2.QtWidgets.QGraphicsWidget.layoutChanged()露
- PySide2.QtWidgets.QGraphicsWidget.layoutDirection()露
- Return type:
This property holds the layout direction for this widget..
This property modifies this widget鈥檚 and all of its descendants鈥
WA_RightToLeftattribute. It also sets this widget鈥檚WA_SetLayoutDirectionattribute.The widget鈥檚 layout direction determines the order in which the layout manager horizontally arranges subwidgets of this widget. The default value depends on the language and locale of the application, and is typically in the same direction as words are read and written. With
LeftToRight, the layout starts placing subwidgets from the left side of this widget towards the right.RightToLeftdoes the opposite - the layout will place widgets starting from the right edge moving towards the left.Subwidgets inherit their layout direction from the parent. Top-level widget items inherit their layout direction from QGraphicsScene::layoutDirection. If you change a widget鈥檚 layout direction by calling , the widget will send itself a
LayoutDirectionChangeevent, and then propagate the new layout direction to all its descendants.See also
layoutDirectionlayoutDirection
- PySide2.QtWidgets.QGraphicsWidget.moveEvent(event)露
- Parameters:
This event handler, for
GraphicsSceneMoveevents, is delivered after the widget has moved (e.g., its local position has changed).This event is only delivered when the item is moved locally. Calling
setTransform()or moving any of the item鈥檚 ancestors does not affect the item鈥檚 local position.You can reimplement this event handler to detect when your widget has moved. Calling
accept()orignore()oneventhas no effect.See also
ItemPositionChangeItemPositionHasChanged
- PySide2.QtWidgets.QGraphicsWidget.paintWindowFrame(painter, option[, widget=None])露
- Parameters:
painter 鈥
PySide2.QtGui.QPainterwidget 鈥
PySide2.QtWidgets.QWidget
This virtual function is called by
QGraphicsSceneto draw the window frame for windows usingpainter,option, andwidget, in local coordinates. The base implementation uses the current style to render the frame and title bar.You can reimplement this function in a subclass of QGraphicsWidget to provide custom rendering of the widget鈥檚 window frame.
See also
- PySide2.QtWidgets.QGraphicsWidget.palette()露
- Return type:
This property holds the widget鈥檚 palette.
This property provides the widget鈥檚 palette. The palette provides colors and brushes for color groups (e.g.,
Button) and states (e.g.,Inactive), loosely defining the general look of the widget and its children.QPaletteconsists of color groups that have been explicitly defined, and groups that are implicitly inherited from the widget鈥檚 parent. Because of this, can return a different palette than what has been set with . This scheme allows you to define single entries in a palette without affecting the palette鈥檚 inherited entries.When a widget鈥檚 palette changes, it resolves its entries against its parent widget, or if it doesn鈥檛 have a parent widget, it resolves against the scene. It then sends itself a
PaletteChangeevent, and notifies all its descendants so they can resolve their palettes as well.By default, this property contains the application鈥檚 default palette.
See also
palette()paletteresolve()
- PySide2.QtWidgets.QGraphicsWidget.polishEvent()露
This event is delivered to the item by the scene at some point after it has been constructed, but before it is shown or otherwise accessed through the scene. You can use this event handler to do last-minute initializations of the widget which require the item to be fully constructed.
The base implementation does nothing.
- PySide2.QtWidgets.QGraphicsWidget.propertyChange(propertyName, value)露
- Parameters:
propertyName 鈥 str
value 鈥 object
- Return type:
object
This virtual function is used to notify changes to any property (both dynamic properties, and registered with
Q_PROPERTY) in the widget. Depending on the property itself, the notification can be delivered before or after the value has changed.propertyNameis the name of the property (e.g., 鈥渟ize鈥 or 鈥渇ont鈥), andvalueis the (proposed) new value of the property. The function returns the new value, which may be different fromvalueif the notification supports adjusting the property value. The base implementation simply returnsvaluefor anypropertyName.QGraphicsWidget delivers notifications for the following properties:
propertyName
Property
size
font
palette
See also
itemChange()
- PySide2.QtWidgets.QGraphicsWidget.rect()露
- Return type:
Returns the item鈥檚 local rect as a
QRectF. This function is equivalent toQRectF(QPointF(),size()).See also
- PySide2.QtWidgets.QGraphicsWidget.releaseShortcut(id)露
- Parameters:
id 鈥 int
Removes the shortcut with the given
idfrom Qt鈥檚 shortcut system. The widget will no longer receiveShortcutevents for the shortcut鈥檚 key sequence (unless it has other shortcuts with the same key sequence).Warning
You should not normally need to use this function since Qt鈥檚 shortcut system removes shortcuts automatically when their parent widget is destroyed. It is best to use
QActionorQShortcutto handle shortcuts, since they are easier to use than this low-level function. Note also that this is an expensive operation.
- PySide2.QtWidgets.QGraphicsWidget.removeAction(action)露
- Parameters:
action 鈥
PySide2.QtWidgets.QAction
Removes the action
actionfrom this widget鈥檚 list of actions.
- PySide2.QtWidgets.QGraphicsWidget.resize(size)露
- Parameters:
size 鈥
PySide2.QtCore.QSizeF
This property holds the size of the widget.
Calling resizes the widget to a
sizebounded byminimumSize()andmaximumSize(). This property only affects the widget鈥檚 width and height (e.g., its right and bottom edges); the widget鈥檚 position and top-left corner remains unaffected.Resizing a widget triggers the widget to immediately receive a
GraphicsSceneResizeevent with the widget鈥檚 old and new size. If the widget has a layout assigned when this event arrives, the layout will be activated and it will automatically update any child widgets鈥檚 geometry.This property does not affect any layout of the parent widget. If the widget itself is managed by a parent layout; e.g., it has a parent widget with a layout assigned, that layout will not activate.
By default, this property contains a size with zero width and height.
- PySide2.QtWidgets.QGraphicsWidget.resize(w, h)
- Parameters:
w 鈥 float
h 鈥 float
This is an overloaded function.
Constructs a resize with the given
width(w) andheight(h). This convenience function is equivalent to calling resize(QSizeF(w, h)).See also
setGeometry()setTransform()
- PySide2.QtWidgets.QGraphicsWidget.resizeEvent(event)露
- Parameters:
This event handler, for
GraphicsSceneResizeevents, is delivered after the widget has been resized (i.e., its local size has changed).eventcontains both the old and the new size.This event is only delivered when the widget is resized locally; calling
setTransform()on the widget or any of its ancestors or view, does not affect the widget鈥檚 local size.You can reimplement this event handler to detect when your widget has been resized. Calling
accept()orignore()oneventhas no effect.See also
- PySide2.QtWidgets.QGraphicsWidget.setAttribute(attribute[, on=true])露
- Parameters:
attribute 鈥
WidgetAttributeon 鈥 bool
If
onis true, this function enablesattribute; otherwiseattributeis disabled.See the class documentation for QGraphicsWidget for a complete list of which attributes are supported, and what they are for.
See also
- PySide2.QtWidgets.QGraphicsWidget.setAutoFillBackground(enabled)露
- Parameters:
enabled 鈥 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()method. The color used is defined by theWindowcolor role from the widget鈥檚palette.In addition, Windows are always filled with
Window, unless the WA_OpaquePaintEvent or WA_NoSystemBackground attributes are set.By default, this property is
false.See also
WA_OpaquePaintEventWA_NoSystemBackground
- PySide2.QtWidgets.QGraphicsWidget.setContentsMargins(margins)露
- Parameters:
margins 鈥
PySide2.QtCore.QMarginsF
Sets the widget鈥檚 contents margins to
margins.Contents margins are used by the assigned layout to define the placement of subwidgets and layouts. Margins are particularly useful for widgets that constrain subwidgets to only a section of its own geometry. For example, a group box with a layout will place subwidgets inside its frame, but below the title.
Changing a widget鈥檚 contents margins will always trigger an
update(), and any assigned layout will be activated automatically. The widget will then receive aContentsRectChangeevent.See also
getContentsMargins()setGeometry()
- PySide2.QtWidgets.QGraphicsWidget.setContentsMargins(left, top, right, bottom)
- Parameters:
left 鈥 float
top 鈥 float
right 鈥 float
bottom 鈥 float
This is an overloaded function.
Sets the widget鈥檚 contents margins to
left,top,rightandbottom.
- PySide2.QtWidgets.QGraphicsWidget.setFocusPolicy(policy)露
- Parameters:
policy 鈥
FocusPolicy
This property holds the way the widget accepts keyboard focus.
The focus policy is
TabFocusif the widget accepts keyboard focus by tabbing,ClickFocusif the widget accepts focus by clicking,StrongFocusif it accepts both, andNoFocus(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鈥檚 constructor. For instance, the
QLineEditconstructor calls (StrongFocus).If you enable a focus policy (i.e., not
NoFocus), QGraphicsWidget will automatically enable theItemIsFocusableflag. SettingNoFocuson a widget will clear theItemIsFocusableflag. If the widget currently has keyboard focus, the widget will automatically lose focus.See also
focusInEvent()focusOutEvent()keyPressEvent()keyReleaseEvent()enabled
- PySide2.QtWidgets.QGraphicsWidget.setFont(font)露
- Parameters:
font 鈥
PySide2.QtGui.QFont
This property holds the widgets鈥 font.
This property provides the widget鈥檚 font.
QFontconsists of font properties that have been explicitly defined and properties implicitly inherited from the widget鈥檚 parent. Hence, can return a different font compared to the one set with . This scheme allows you to define single entries in a font without affecting the font鈥檚 inherited entries.When a widget鈥檚 font changes, it resolves its entries against its parent widget. If the widget does not have a parent widget, it resolves its entries against the scene. The widget then sends itself a
FontChangeevent and notifies all its descendants so that they can resolve their fonts as well.By default, this property contains the application鈥檚 default font.
- PySide2.QtWidgets.QGraphicsWidget.setGeometry(x, y, w, h)露
- Parameters:
x 鈥 float
y 鈥 float
w 鈥 float
h 鈥 float
This convenience function is equivalent to calling
setGeometry(QRectF(x,y,w,h)).See also
- PySide2.QtWidgets.QGraphicsWidget.setLayout(layout)露
- Parameters:
layout 鈥
PySide2.QtWidgets.QGraphicsLayout
This property holds The layout of the widget.
Any existing layout manager is deleted before the new layout is assigned. If
layoutisNone, the widget is left without a layout. Existing subwidgets鈥 geometries will remain unaffected.QGraphicsWidget takes ownership of
layout.All widgets that are currently managed by
layoutor all of its sublayouts, are automatically reparented to this item. The layout is then invalidated, and the child widget geometries are adjusted according to this item鈥檚geometry()and contentsMargins(). Children who are not explicitly managed bylayoutremain unaffected by the layout after it has been assigned to this widget.If no layout is currently managing this widget,
layout()will returnNone.
- PySide2.QtWidgets.QGraphicsWidget.setLayoutDirection(direction)露
- Parameters:
direction 鈥
LayoutDirection
This property holds the layout direction for this widget..
This property modifies this widget鈥檚 and all of its descendants鈥
WA_RightToLeftattribute. It also sets this widget鈥檚WA_SetLayoutDirectionattribute.The widget鈥檚 layout direction determines the order in which the layout manager horizontally arranges subwidgets of this widget. The default value depends on the language and locale of the application, and is typically in the same direction as words are read and written. With
LeftToRight, the layout starts placing subwidgets from the left side of this widget towards the right.RightToLeftdoes the opposite - the layout will place widgets starting from the right edge moving towards the left.Subwidgets inherit their layout direction from the parent. Top-level widget items inherit their layout direction from QGraphicsScene::layoutDirection. If you change a widget鈥檚 layout direction by calling , the widget will send itself a
LayoutDirectionChangeevent, and then propagate the new layout direction to all its descendants.See also
layoutDirectionlayoutDirection
- PySide2.QtWidgets.QGraphicsWidget.setPalette(palette)露
- Parameters:
palette 鈥
PySide2.QtGui.QPalette
This property holds the widget鈥檚 palette.
This property provides the widget鈥檚 palette. The palette provides colors and brushes for color groups (e.g.,
Button) and states (e.g.,Inactive), loosely defining the general look of the widget and its children.QPaletteconsists of color groups that have been explicitly defined, and groups that are implicitly inherited from the widget鈥檚 parent. Because of this, can return a different palette than what has been set with . This scheme allows you to define single entries in a palette without affecting the palette鈥檚 inherited entries.When a widget鈥檚 palette changes, it resolves its entries against its parent widget, or if it doesn鈥檛 have a parent widget, it resolves against the scene. It then sends itself a
PaletteChangeevent, and notifies all its descendants so they can resolve their palettes as well.By default, this property contains the application鈥檚 default palette.
See also
palette()paletteresolve()
- PySide2.QtWidgets.QGraphicsWidget.setShortcutAutoRepeat(id[, enabled=true])露
- Parameters:
id 鈥 int
enabled 鈥 bool
If
enabledis true, auto repeat of the shortcut with the givenidis enabled; otherwise it is disabled.
- PySide2.QtWidgets.QGraphicsWidget.setShortcutEnabled(id[, enabled=true])露
- Parameters:
id 鈥 int
enabled 鈥 bool
If
enabledis true, the shortcut with the givenidis enabled; otherwise the shortcut is disabled.Warning
You should not normally need to use this function since Qt鈥檚 shortcut system enables/disables shortcuts automatically as widgets become hidden/visible and gain or lose focus. It is best to use
QActionorQShortcutto handle shortcuts, since they are easier to use than this low-level function.
- PySide2.QtWidgets.QGraphicsWidget.setStyle(style)露
- Parameters:
style 鈥
PySide2.QtWidgets.QStyle
Sets the widget鈥檚 style to
style. QGraphicsWidget does not take ownership ofstyle.If no style is assigned, or
styleisNone, the widget will usestyle()(if this has been set). Otherwise the widget will usestyle().This function sets the
WA_SetStyleattribute ifstyleis notNone; otherwise it clears the attribute.See also
- static PySide2.QtWidgets.QGraphicsWidget.setTabOrder(first, second)露
- Parameters:
second 鈥
PySide2.QtWidgets.QGraphicsWidget
Moves the
secondwidget around the ring of focus widgets so that keyboard focus moves from thefirstwidget to thesecondwidget when the Tab key is pressed.Note that since the tab order of the
secondwidget is changed, you should order a chain like this:setTabOrder(a, b) # a to b setTabOrder(b, c) # a to b to c setTabOrder(c, d) # a to b to c to d
not like this:
# WRONG setTabOrder(c, d) # c to d setTabOrder(a, b) # a to b AND c to d setTabOrder(b, c) # a to b to c, but not c to d
If
firstisNone, this indicates thatsecondshould be the first widget to receive input focus should the scene gain Tab focus (i.e., the user hits Tab so that focus passes into the scene). IfsecondisNone, this indicates thatfirstshould be the first widget to gain focus if the scene gained BackTab focus.By default, tab order is defined implicitly using widget creation order.
See also
- PySide2.QtWidgets.QGraphicsWidget.setWindowFlags(wFlags)露
- Parameters:
wFlags 鈥
WindowFlags
This property holds the widget鈥檚 window flags.
Window flags are a combination of a window type (e.g.,
Dialog) and several flags giving hints on the behavior of the window. The behavior is platform-dependent.By default, this property contains no window flags.
Windows are panels. If you set the
Windowflag, theItemIsPanelflag will be set automatically. If you clear theWindowflag, theItemIsPanelflag is also cleared. Note that theItemIsPanelflag can be set independently ofWindow.See also
isWindow()isPanel()
- PySide2.QtWidgets.QGraphicsWidget.setWindowFrameMargins(margins)露
- Parameters:
margins 鈥
PySide2.QtCore.QMarginsF
Sets the widget鈥檚 window frame margins to
margins. The default frame margins are provided by the style, and they depend on the current window flags.If you would like to draw your own window decoration, you can set your own frame margins to override the default margins.
- PySide2.QtWidgets.QGraphicsWidget.setWindowFrameMargins(left, top, right, bottom)
- Parameters:
left 鈥 float
top 鈥 float
right 鈥 float
bottom 鈥 float
This is an overloaded function.
Sets the widget鈥檚 window frame margins to
left,top,rightandbottom.
- PySide2.QtWidgets.QGraphicsWidget.setWindowTitle(title)露
- Parameters:
title 鈥 str
This property holds This property holds the window title (caption)..
This property is only used for windows.
By default, if no title has been set, this property contains an empty string.
- PySide2.QtWidgets.QGraphicsWidget.showEvent(event)露
- Parameters:
event 鈥
PySide2.QtGui.QShowEvent
This event handler, for
Showevents, is delivered before the widget has been shown, for example,setVisible(true) has been called for the widget or one of its ancestors when the widget was previously hidden.You can reimplement this event handler to detect when your widget is shown. Calling
accept()orignore()oneventhas no effect.See also
hideEvent()showEvent()ItemVisibleChange
- PySide2.QtWidgets.QGraphicsWidget.size()露
- Return type:
This property holds the size of the widget.
Calling resizes the widget to a
sizebounded byminimumSize()andmaximumSize(). This property only affects the widget鈥檚 width and height (e.g., its right and bottom edges); the widget鈥檚 position and top-left corner remains unaffected.Resizing a widget triggers the widget to immediately receive a
GraphicsSceneResizeevent with the widget鈥檚 old and new size. If the widget has a layout assigned when this event arrives, the layout will be activated and it will automatically update any child widgets鈥檚 geometry.This property does not affect any layout of the parent widget. If the widget itself is managed by a parent layout; e.g., it has a parent widget with a layout assigned, that layout will not activate.
By default, this property contains a size with zero width and height.
- PySide2.QtWidgets.QGraphicsWidget.style()露
- Return type:
Returns a pointer to the widget鈥檚 style. If this widget does not have any explicitly assigned style, the scene鈥檚 style is returned instead. In turn, if the scene does not have any assigned style, this function returns
style().See also
- PySide2.QtWidgets.QGraphicsWidget.testAttribute(attribute)露
- Parameters:
attribute 鈥
WidgetAttribute- Return type:
bool
Returns
trueifattributeis enabled for this widget; otherwise, returnsfalse.See also
- PySide2.QtWidgets.QGraphicsWidget.ungrabKeyboardEvent(event)露
- Parameters:
event 鈥
PySide2.QtCore.QEvent
This event handler, for
event, can be reimplemented in a subclass to receive notifications forUngrabKeyboardevents.See also
ungrabKeyboard()ungrabMouse()
- PySide2.QtWidgets.QGraphicsWidget.ungrabMouseEvent(event)露
- Parameters:
event 鈥
PySide2.QtCore.QEvent
This event handler, for
event, can be reimplemented in a subclass to receive notifications forUngrabMouseevents.See also
ungrabMouse()ungrabKeyboard()
- PySide2.QtWidgets.QGraphicsWidget.unsetLayoutDirection()露
This property holds the layout direction for this widget..
This property modifies this widget鈥檚 and all of its descendants鈥
WA_RightToLeftattribute. It also sets this widget鈥檚WA_SetLayoutDirectionattribute.The widget鈥檚 layout direction determines the order in which the layout manager horizontally arranges subwidgets of this widget. The default value depends on the language and locale of the application, and is typically in the same direction as words are read and written. With
LeftToRight, the layout starts placing subwidgets from the left side of this widget towards the right.RightToLeftdoes the opposite - the layout will place widgets starting from the right edge moving towards the left.Subwidgets inherit their layout direction from the parent. Top-level widget items inherit their layout direction from QGraphicsScene::layoutDirection. If you change a widget鈥檚 layout direction by calling , the widget will send itself a
LayoutDirectionChangeevent, and then propagate the new layout direction to all its descendants.See also
layoutDirectionlayoutDirection
- PySide2.QtWidgets.QGraphicsWidget.unsetWindowFrameMargins()露
Resets the window frame margins to the default value, provided by the style.
- PySide2.QtWidgets.QGraphicsWidget.windowFlags()露
- Return type:
WindowFlags
This property holds the widget鈥檚 window flags.
Window flags are a combination of a window type (e.g.,
Dialog) and several flags giving hints on the behavior of the window. The behavior is platform-dependent.By default, this property contains no window flags.
Windows are panels. If you set the
Windowflag, theItemIsPanelflag will be set automatically. If you clear theWindowflag, theItemIsPanelflag is also cleared. Note that theItemIsPanelflag can be set independently ofWindow.See also
isWindow()isPanel()
- PySide2.QtWidgets.QGraphicsWidget.windowFrameEvent(e)露
- Parameters:
- Return type:
bool
This event handler, for
event, receives events for the window frame if this widget is a window. Its base implementation provides support for default window frame interaction such as moving, resizing, etc.You can reimplement this handler in a subclass of QGraphicsWidget to provide your own custom window frame interaction support.
Returns
trueifeventhas been recognized and processed; otherwise, returnsfalse.See also
event()
- PySide2.QtWidgets.QGraphicsWidget.windowFrameGeometry()露
- Return type:
Returns the widget鈥檚 geometry in parent coordinates including any window frame.
- PySide2.QtWidgets.QGraphicsWidget.windowFrameRect()露
- Return type:
Returns the widget鈥檚 local rect including any window frame.
- PySide2.QtWidgets.QGraphicsWidget.windowFrameSectionAt(pos)露
- Parameters:
pos 鈥
PySide2.QtCore.QPointF- Return type:
Returns the window frame section at position
pos, orNoSectionif there is no window frame section at this position.This function is used in QGraphicsWidget 鈥榮 base implementation for window frame interaction.
You can reimplement this function if you want to customize how a window can be interactively moved or resized. For instance, if you only want to allow a window to be resized by the bottom right corner, you can reimplement this function to return
NoSectionfor all sections exceptBottomRightSection.
- PySide2.QtWidgets.QGraphicsWidget.windowTitle()露
- Return type:
str
This property holds This property holds the window title (caption)..
This property is only used for windows.
By default, if no title has been set, this property contains an empty string.
- PySide2.QtWidgets.QGraphicsWidget.windowType()露
- Return type:
Returns the widgets window type.
See also
windowFlags()isWindow()isPanel()
漏 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.