QGraphicsWidget 類

The QGraphicsWidget 類是基類用於所有 Widget 項在 QGraphicsScene . 更多...

頭: #include <QGraphicsWidget>
qmake: QT += widgets
Since: Qt 4.4
繼承: QGraphicsObject and QGraphicsLayoutItem
繼承者: QChart , QGraphicsProxyWidget ,和 QLegend

特性

公共函數

QGraphicsWidget (QGraphicsItem * parent = Q_NULLPTR, Qt::WindowFlags wFlags = Qt::WindowFlags())
~QGraphicsWidget ()
QList<QAction *> actions () const
void addAction (QAction * action )
void addActions (QList<QAction *> actions )
void adjustSize ()
bool autoFillBackground () const
Qt::FocusPolicy focusPolicy () const
QGraphicsWidget * focusWidget () const
QFont font () const
void getWindowFrameMargins (qreal * left , qreal * top , qreal * right , qreal * bottom ) const
int grabShortcut (const QKeySequence & sequence , Qt::ShortcutContext context = Qt::WindowShortcut)
void insertAction (QAction * before , QAction * action )
void insertActions (QAction * before , QList<QAction *> actions )
bool isActiveWindow () const
QGraphicsLayout * layout () const
Qt::LayoutDirection layoutDirection () const
virtual void paintWindowFrame (QPainter * painter , const QStyleOptionGraphicsItem * option , QWidget * widget = Q_NULLPTR)
QPalette palette () const
QRectF rect () const
void releaseShortcut (int id )
void removeAction (QAction * action )
void resize (const QSizeF & size )
void resize (qreal w , qreal h )
void setAttribute (Qt::WidgetAttribute attribute , bool on = true)
void setAutoFillBackground (bool enabled )
void setContentsMargins (qreal left , qreal top , qreal right , qreal bottom )
void setFocusPolicy (Qt::FocusPolicy policy )
void setFont (const QFont & font )
void setGeometry (qreal x , qreal y , qreal w , qreal h )
void setLayout (QGraphicsLayout * layout )
void setLayoutDirection (Qt::LayoutDirection direction )
void setPalette (const QPalette & palette )
void setShortcutAutoRepeat (int id , bool enabled = true)
void setShortcutEnabled (int id , bool enabled = true)
void setStyle (QStyle * style )
void setWindowFlags (Qt::WindowFlags wFlags )
void setWindowFrameMargins (qreal left , qreal top , qreal right , qreal bottom )
void setWindowTitle (const QString & title )
QSizeF size () const
QStyle * style () const
bool testAttribute (Qt::WidgetAttribute attribute ) const
void unsetLayoutDirection ()
void unsetWindowFrameMargins ()
Qt::WindowFlags windowFlags () const
QRectF windowFrameGeometry () const
QRectF windowFrameRect () const
QString windowTitle () const
Qt::WindowType windowType () const

重實現公共函數

virtual QRectF boundingRect () const
virtual void getContentsMargins (qreal * left , qreal * top , qreal * right , qreal * bottom ) const
virtual void paint (QPainter * painter , const QStyleOptionGraphicsItem * option , QWidget * widget = Q_NULLPTR)
virtual void setGeometry (const QRectF & rect )
virtual QPainterPath shape () const
virtual int type () const

公共槽

bool close ()

信號

void geometryChanged ()

靜態公共成員

void setTabOrder (QGraphicsWidget * first , QGraphicsWidget * second )

保護函數

virtual void changeEvent (QEvent * event )
virtual void closeEvent (QCloseEvent * event )
virtual bool focusNextPrevChild (bool next )
virtual void grabKeyboardEvent (QEvent * event )
virtual void grabMouseEvent (QEvent * event )
virtual void hideEvent (QHideEvent * event )
virtual void initStyleOption (QStyleOption * option ) const
virtual void moveEvent (QGraphicsSceneMoveEvent * event )
virtual void polishEvent ()
virtual void resizeEvent (QGraphicsSceneResizeEvent * event )
virtual void showEvent (QShowEvent * event )
virtual void ungrabKeyboardEvent (QEvent * event )
virtual void ungrabMouseEvent (QEvent * event )
virtual bool windowFrameEvent (QEvent * event )
virtual Qt::WindowFrameSection windowFrameSectionAt (const QPointF & pos ) const

重實現保護函數

virtual bool event (QEvent * event )
virtual void focusInEvent (QFocusEvent * event )
virtual void focusOutEvent (QFocusEvent * event )
virtual void hoverLeaveEvent (QGraphicsSceneHoverEvent * event )
virtual void hoverMoveEvent (QGraphicsSceneHoverEvent * event )
virtual QVariant itemChange (GraphicsItemChange change , const QVariant & value )
virtual bool sceneEvent (QEvent * event )
virtual QSizeF sizeHint (Qt::SizeHint which , const QSizeF & constraint = QSizeF()) const
virtual void updateGeometry ()

額外繼承成員

詳細描述

The QGraphicsWidget 類是基類用於所有 Widget 項在 QGraphicsScene .

QGraphicsWidget 是提供額外功能的擴展基項基於 QGraphicsItem 。類似於 QWidget 在很多方麵:

不像 QGraphicsItem , QGraphicsWidget 不是抽象類;可以創建實例化的 QGraphicsWidget 不必子類化它。這種方式對於僅將子級 Widget 組織到布局的小部件很有用。

QGraphicsWidget 可以用作自己的自定義項的基項,若要求高級輸入聚焦處理 (如:Tab 聚焦和激活或布局)。

由於 QGraphicsWidget 類似於 QWidget 且擁有同樣的 API,更容易於移植 Widget 從 QWidget to QGraphicsWidget ,而不是 QGraphicsItem .

注意: QWidget 基 Widget 可以直接嵌入 QGraphicsScene 使用 QGraphicsProxyWidget .

明顯差異在 QGraphicsWidget and QWidget 是:

QGraphicsWidget QWidget
坐標和幾何體按 qreal 定義 (雙精度或浮點數,從屬平颱)。 QWidget 使用整數幾何體 ( QPoint , QRect ).
小部件默認情況下已可見;不必調用 show () 來顯示 Widget。 QWidget 默認情況下是隱藏的,直到調用 show ().
支持 Widget 屬性子集。 支持所有 Widget 屬性。
頂層項的樣式默認為 QGraphicsScene::style 頂層 Widget 的樣式默認為 QApplication::style
Graphics View 提供自定義拖放框架,不同於 QWidget . 標準拖放框架。
Widget 項不支持模態。 完整模態支持。

QGraphicsWidget 支持 Qt 小部件屬性子集,( Qt::WidgetAttribute ),如下錶所示。此錶中未列齣的任何屬性,不受支持或不使用。

Widget 屬性 用法
Qt::WA_SetLayoutDirection 設置通過 setLayoutDirection (), cleared by unsetLayoutDirection (). You can test this attribute to check if the widget has been explicitly assigned a layoutDirection . If the attribute is not set, the layoutDirection() is inherited.
Qt::WA_RightToLeft Toggled by setLayoutDirection (). Inherited from the parent/scene. If set, the widget's layout will order horizontally arranged widgets from right to left.
Qt::WA_SetStyle Set 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's or the application's style.
Qt::WA_Resized 設置通過 setGeometry () 和 resize ().
Qt::WA_SetPalette 設置通過 setPalette ().
Qt::WA_SetFont 設置通過 setFont ().
Qt::WA_WindowPropagation 允許傳播到窗口 Widget。

盡管 QGraphicsWidget inherits from both QObject and QGraphicsItem ,應使用函數提供通過 QGraphicsItem , not QObject ,來管理父級和子級項之間的關係。這些函數控製項的堆疊次序及它們的所有權。

注意: The QObject::parent () should always return 0 for QGraphicsWidgets, but this policy is not strictly defined.

另請參閱 QGraphicsProxyWidget , QGraphicsItem ,和 Widget 和布局 .

特性文檔編製

autoFillBackground : bool

此特性保持是否自動填充 Widget 背景

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 the QPalette::Window 顔色角色來自 Widget 的 palette .

此外,填充窗口總是采用 QPalette::Window ,除非有設置 WA_OpaquePaintEvent (或 WA_NoSystemBackground) 屬性。

默認情況下,此特性為 false .

該特性在 Qt 4.7 引入。

訪問函數:

bool autoFillBackground () const
void setAutoFillBackground (bool enabled )

另請參閱 Qt::WA_OpaquePaintEvent and Qt::WA_NoSystemBackground .

focusPolicy : Qt::FocusPolicy

此特性保持 Widget 接受鍵盤聚焦的方式

The focus policy is Qt::TabFocus 若 Widget 通過 Tab 鍵接受鍵盤聚焦, Qt::ClickFocus 若 Widget 通過點擊接受聚焦, Qt::StrongFocus 若它接受兩者,而 Qt::NoFocus (默認) 若它根本不接受聚焦。

必須為 Widget 啓用鍵盤聚焦,若它處理鍵盤事件。通常這是由 Widget 構造函數完成的。例如, QLineEdit 構造函數調用 setFocusPolicy( Qt::StrongFocus ).

If you enable a focus policy (i.e., not Qt::NoFocus ), QGraphicsWidget will automatically enable the ItemIsFocusable flag. Setting Qt::NoFocus on a widget will clear the ItemIsFocusable flag. If the widget currently has keyboard focus, the widget will automatically lose focus.

訪問函數:

Qt::FocusPolicy focusPolicy () const
void setFocusPolicy (Qt::FocusPolicy policy )

另請參閱 focusInEvent (), focusOutEvent (), keyPressEvent (), keyReleaseEvent (),和 enabled .

font : QFont

This property holds the widgets' font

This property provides the widget's font.

QFont consists of font properties that have been explicitly defined and properties implicitly inherited from the widget's parent. Hence, font() can return a different font compared to the one set with setFont(). This scheme allows you to define single entries in a font without affecting the font's inherited entries.

When a widget's 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 FontChange event and notifies all its descendants so that they can resolve their fonts as well.

默認情況下,此特性包含應用程序默認字體。

訪問函數:

QFont font () const
void setFont (const QFont & font )

另請參閱 QApplication::font (), QGraphicsScene::font ,和 QFont::resolve ().

geometry : QRectF

This property holds the geometry of the widget

Sets the item's geometry to rect . The item's position and size are modified as a result of calling this function. The item is first moved, then resized.

A side effect of calling this function is that the widget will receive a move event and a resize event. Also, if the widget has a layout assigned, the layout will activate.

訪問函數:

virtual void setGeometry (const QRectF & rect )
void setGeometry (qreal x , qreal y , qreal w , qreal h )

通知程序信號:

void geometryChanged ()

另請參閱 geometry () 和 resize ().

layout : QGraphicsLayout *

This property holds the layout of the widget

Any existing layout manager is deleted before the new layout is assigned. If layout is 0, the widget is left without a layout. Existing subwidgets' geometries will remain unaffected.

QGraphicsWidget 擁有所有權對於 layout .

All widgets that are currently managed by layout or 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's geometry () and contentsMargins(). Children who are not explicitly managed by layout remain unaffected by the layout after it has been assigned to this widget.

If no layout is currently managing this widget, layout () will return 0.

訪問函數:

QGraphicsLayout * layout () const
void setLayout (QGraphicsLayout * layout )

layoutDirection : Qt::LayoutDirection

此特性保持此 Widget 的布局方嚮。

This property modifies this widget's and all of its descendants' Qt::WA_RightToLeft attribute. It also sets this widget's Qt::WA_SetLayoutDirection 屬性。

The widget's 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 Qt::LeftToRight , the layout starts placing subwidgets from the left side of this widget towards the right. Qt::RightToLeft does 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's layout direction by calling setLayoutDirection(), the widget will send itself a LayoutDirectionChange event, and then propagate the new layout direction to all its descendants.

訪問函數:

Qt::LayoutDirection layoutDirection () const
void setLayoutDirection (Qt::LayoutDirection direction )
void unsetLayoutDirection ()

另請參閱 QWidget::layoutDirection and QApplication::layoutDirection .

maximumSize : const QSizeF

This property holds the maximum size of the widget

另請參閱 setMaximumSize (), maximumSize (), minimumSize ,和 preferredSize .

minimumSize : const QSizeF

This property holds the minimum size of the widget

另請參閱 setMinimumSize (), minimumSize (), preferredSize ,和 maximumSize .

palette : QPalette

此特性保持 Widget 的調色闆

This property provides the widget's palette. The palette provides colors and brushes for color groups (e.g., QPalette::Button ) and states (e.g., QPalette::Inactive ), loosely defining the general look of the widget and its children.

QPalette consists of color groups that have been explicitly defined, and groups that are implicitly inherited from the widget's parent. Because of this, palette() can return a different palette than what has been set with setPalette(). This scheme allows you to define single entries in a palette without affecting the palette's inherited entries.

When a widget's palette changes, it resolves its entries against its parent widget, or if it doesn't have a parent widget, it resolves against the scene. It then sends itself a PaletteChange event, and notifies all its descendants so they can resolve their palettes as well.

By default, this property contains the application's default palette.

訪問函數:

QPalette palette () const
void setPalette (const QPalette & palette )

另請參閱 QApplication::palette (), QGraphicsScene::palette ,和 QPalette::resolve ().

preferredSize : const QSizeF

This property holds the preferred size of the widget

另請參閱 setPreferredSize (), preferredSize (), minimumSize ,和 maximumSize .

size : QSizeF

This property holds the size of the widget

Calling resize() resizes the widget to a size bounded by minimumSize () 和 maximumSize (). This property only affects the widget's width and height (e.g., its right and bottom edges); the widget's position and top-left corner remains unaffected.

Resizing a widget triggers the widget to immediately receive a GraphicsSceneResize event with the widget's 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's 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.

默認情況下,此特性包含 0 大小寬度和高度。

訪問函數:

QSizeF size () const
void resize (const QSizeF & size )
void resize (qreal w , qreal h )

通知程序信號:

void geometryChanged ()

另請參閱 setGeometry (), QGraphicsSceneResizeEvent ,和 QGraphicsLayout .

sizePolicy : const QSizePolicy

This property holds the size policy for the widget

另請參閱 sizePolicy (), setSizePolicy (),和 QWidget::sizePolicy ().

windowFlags : Qt::WindowFlags

This property holds the widget's window flags

Window flags are a combination of a window type (e.g., Qt::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 Qt::Window flag, the ItemIsPanel flag will be set automatically. If you clear the Qt::Window flag, the ItemIsPanel flag is also cleared. Note that the ItemIsPanel flag can be set independently of Qt::Window .

訪問函數:

Qt::WindowFlags windowFlags () const
void setWindowFlags (Qt::WindowFlags wFlags )

另請參閱 isWindow () 和 isPanel ().

windowTitle : QString

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.

訪問函數:

QString windowTitle () const
void setWindowTitle (const QString & title )

成員函數文檔編製

QGraphicsWidget:: QGraphicsWidget ( QGraphicsItem * parent = Q_NULLPTR, Qt::WindowFlags wFlags = Qt::WindowFlags())

構造 QGraphicsWidget instance. The optional parent 自變量會被傳遞給 QGraphicsItem 's constructor. The optional wFlags argument specifies the widget's window flags (e.g., whether the widget should be a window, a tool, a popup, etc).

QGraphicsWidget:: ~QGraphicsWidget ()

銷毀 QGraphicsWidget 實例。

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

返迴此 Widget 的動作列錶 (可能為空)。

該函數在 Qt 4.5 引入。

另請參閱 insertAction (), removeAction (), QWidget::actions (), QAction::associatedWidgets (),和 QAction::associatedGraphicsWidgets ().

void QGraphicsWidget:: addAction ( QAction * action )

追加動作 action 到此 Widget 的動作列錶。

All QGraphicsWidgets have a list of QAction ,不管怎樣,可以按多種不同方式圖形錶示它們。默認使用 QAction 列錶 (作為返迴通過 actions ()) 創建上下文 QMenu .

A QGraphicsWidget 隻應每動作有一個,且已添加動作不會導緻同一動作在 Widget 中齣現 2 次。

該函數在 Qt 4.5 引入。

另請參閱 removeAction (), insertAction (), actions (),和 QWidget::addAction ().

void QGraphicsWidget:: addActions ( QList < QAction *> actions )

追加動作 actions 到此 Widget 的動作列錶。

該函數在 Qt 4.5 引入。

另請參閱 removeAction (), QMenu , addAction (),和 QWidget::addActions ().

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

另請參閱 effectiveSizeHint () 和 Qt::MinimumSize .

[虛擬] QRectF QGraphicsWidget:: boundingRect () const

重實現自 QGraphicsItem::boundingRect ().

[virtual protected] void QGraphicsWidget:: changeEvent ( QEvent * event )

此事件處理程序可以重實現,以處理狀態改變。

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

改變事件包括: QEvent::ActivationChange , QEvent::EnabledChange , QEvent::FontChange , QEvent::StyleChange , QEvent::PaletteChange , QEvent::ParentChange , QEvent::LayoutDirectionChange ,和 QEvent::ContentsRectChange .

[slot] bool QGraphicsWidget:: close ()

Call this function to close the widget.

返迴 true 若 Widget 被關閉;否則返迴 false . This slot will first send a QCloseEvent to the widget, which may or may not accept the event. If the event was ignored, nothing happens. If the event was accepted, it will hide () the widget.

若 Widget 擁有 Qt::WA_DeleteOnClose attribute set it will be deleted.

[virtual protected] void QGraphicsWidget:: closeEvent ( QCloseEvent * event )

此事件處理程序用於 event , can be reimplemented in a subclass to receive widget close events. The default implementation accepts the event.

另請參閱 close () 和 QCloseEvent .

[virtual protected] bool QGraphicsWidget:: event ( QEvent * event )

重實現自 QObject::event ().

處理 event . QGraphicsWidget handles the following events:

Event 用法
波蘭語 Delivered to the widget some time after it has been shown.
GraphicsSceneMove Delivered to the widget after its local position has changed.
GraphicsSceneResize Delivered to the widget after its size has changed.
Show Delivered to the widget before it has been shown.
Hide Delivered to the widget after it has been hidden.
PaletteChange Delivered to the widget after its palette has changed.
FontChange Delivered to the widget after its font has changed.
EnabledChange Delivered to the widget after its enabled state has changed.
StyleChange Delivered to the widget after its style has changed.
LayoutDirectionChange Delivered to the widget after its layout direction has changed.
ContentsRectChange Delivered to the widget after its contents margins/ contents rect has changed.

[virtual protected] void QGraphicsWidget:: focusInEvent ( QFocusEvent * event )

重實現自 QGraphicsItem::focusInEvent ().

[virtual protected] bool QGraphicsWidget:: focusNextPrevChild ( bool next )

查找新的 Widget 以賦予鍵盤聚焦,如適閤 Tab 和 Shift+Tab,並返迴 true if it can find a new widget; returns false otherwise. If next is true, this function searches forward; if next 為 False,嚮後搜索。

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 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 gain control of focus traversal for all child widgets.

另請參閱 focusPolicy ().

[virtual protected] void QGraphicsWidget:: focusOutEvent ( QFocusEvent * event )

重實現自 QGraphicsItem::focusOutEvent ().

QGraphicsWidget *QGraphicsWidget:: focusWidget () const

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, 0 is returned.

另請參閱 QGraphicsItem::focusItem () 和 QWidget::focusWidget ().

[signal] void QGraphicsWidget:: geometryChanged ()

This signal gets emitted whenever the geometry is changed in setGeometry ().

注意: 通知程序信號對於特性 geometry 。通知程序信號對於特性 size .

[虛擬] void QGraphicsWidget:: getContentsMargins ( qreal * left , qreal * top , qreal * right , qreal * bottom ) const

重實現自 QGraphicsLayoutItem::getContentsMargins ().

Gets the widget's contents margins. The margins are stored in left , top , right and bottom , as pointers to qreals. Each argument can be omitted by passing 0.

另請參閱 setContentsMargins ().

void QGraphicsWidget:: getWindowFrameMargins ( qreal * left , qreal * top , qreal * right , qreal * bottom ) const

Gets the widget's window frame margins. The margins are stored in left , top , right and bottom as pointers to qreals. Each argument can be omitted by passing 0.

另請參閱 setWindowFrameMargins () 和 windowFrameRect ().

[virtual protected] void QGraphicsWidget:: grabKeyboardEvent ( QEvent * event )

此事件處理程序用於 event ,可以在子類中重實現以接收通知為 QEvent::GrabKeyboard 事件。

另請參閱 grabKeyboard () 和 grabMouse ().

[virtual protected] void QGraphicsWidget:: grabMouseEvent ( QEvent * event )

此事件處理程序用於 event ,可以在子類中重實現以接收通知為 QEvent::GrabMouse 事件。

另請參閱 grabMouse () 和 grabKeyboard ().

int QGraphicsWidget:: grabShortcut (const QKeySequence & sequence , Qt::ShortcutContext context = Qt::WindowShortcut)

Adds a shortcut to Qt's shortcut system that watches for the given key sequence 以給定 context 。若 context is Qt::ApplicationShortcut ,快捷方式適用於整個應用程序。否則,要麼本地到此小部件 Qt::WidgetShortcut ,或到窗口自身 Qt::WindowShortcut . For widgets that are not part of a window (i.e., top-level widgets and their children), Qt::WindowShortcut shortcuts apply to the scene.

If the same key sequence has been grabbed by several widgets, when the key sequence occurs a QEvent::Shortcut 事件以不確定次序發送給應用它的所有 Widget,但將 "ambiguous (歧義)" 標誌設為 true。

警告: 通常不需要使用此函數;而是創建 QAction 采用要求的快捷鍵序列 (若還想要等效菜單選項和工具欄按鈕),或創建 QShortcut 若僅僅需要鍵序列。 QAction and QShortcut 會為您處理所有事件過濾,並提供當用戶觸發鍵序列時觸發的信號,所以比此低級函數更易於使用。

該函數在 Qt 4.5 引入。

另請參閱 releaseShortcut (), setShortcutEnabled (),和 QWidget::grabShortcut ().

[virtual protected] void QGraphicsWidget:: hideEvent ( QHideEvent * event )

此事件處理程序用於 Hide events, 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 QEvent::accept () 或 QEvent::ignore () 在 event 不起作用。

另請參閱 showEvent (), QWidget::hideEvent (),和 ItemVisibleChange .

[virtual protected] void QGraphicsWidget:: hoverLeaveEvent ( QGraphicsSceneHoverEvent * event )

重實現自 QGraphicsItem::hoverLeaveEvent ().

[virtual protected] void QGraphicsWidget:: hoverMoveEvent ( QGraphicsSceneHoverEvent * event )

重實現自 QGraphicsItem::hoverMoveEvent ().

[virtual protected] void QGraphicsWidget:: initStyleOption ( QStyleOption * option ) const

Populates a style option object for this widget based on its current state, and stores the output in option . The default implementation populates option with the following properties.

Style Option Property
state & QStyle::State_Enabled Corresponds to QGraphicsItem::isEnabled ().
state & QStyle::State_HasFocus Corresponds to QGraphicsItem::hasFocus ().
state & QStyle::State_MouseOver Corresponds to QGraphicsItem::isUnderMouse ().
direction Corresponds to QGraphicsWidget::layoutDirection ().
rect Corresponds to QGraphicsWidget::rect ().toRect().
palette Corresponds to QGraphicsWidget::palette ().
fontMetrics Corresponds to QFontMetrics ( QGraphicsWidget::font ()).

子類化的 QGraphicsWidget should call the base implementation, and then test the type of option 使用 qstyleoption_cast <>() or test QStyleOption::Type before storing widget-specific options.

例如:

void MyGroupBoxWidget::initStyleOption(QStyleOption *option) const
{
    QGraphicsWidget::initStyleOption(option);
    if (QStyleOptionGroupBox *box = qstyleoption_cast<QStyleOptionGroupBox *>(option)) {
        // Add group box specific state.
        box->flat = isFlat();
        ...
    }
}
					

另請參閱 QStyleOption::initFrom ().

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

插入動作 action 到此 Widget 的動作列錶,前置於動作 before 。它追加動作,若 before is 0 or before 不是有效動作 (對於此 Widget)。

A QGraphicsWidget 每動作隻應有一個。

該函數在 Qt 4.5 引入。

另請參閱 removeAction (), addAction (), QMenu , actions (),和 QWidget::insertActions ().

void QGraphicsWidget:: insertActions ( QAction * before , QList < QAction *> actions )

插入動作 actions 到此 Widget 的動作列錶,前置於動作 before 。它追加動作,若 before is 0 or before 不是有效動作 (對於此 Widget)。

A QGraphicsWidget 每動作最多能有一個。

該函數在 Qt 4.5 引入。

另請參閱 removeAction (), QMenu , insertAction (),和 QWidget::insertActions ().

bool QGraphicsWidget:: isActiveWindow () const

返迴 true if this widget's 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.

另請參閱 QGraphicsScene::activeWindow (), QGraphicsScene::setActiveWindow (),和 isActive ().

[virtual protected] QVariant QGraphicsWidget:: itemChange ( GraphicsItemChange change , const QVariant & value )

重實現自 QGraphicsItem::itemChange ().

QGraphicsWidget uses the base implementation of this function to catch and deliver events related to state changes in the item. Because of this, it is very important that subclasses call the base implementation.

change specifies the type of change, and value is the new value.

例如, QGraphicsWidget 使用 ItemVisibleChange to deliver Show and Hide events, ItemPositionHasChanged to deliver Move events, and ItemParentChange both to deliver ParentChange events, and for managing the focus chain.

QGraphicsWidget 啓用 ItemSendsGeometryChanges flag by default in order to track position changes.

另請參閱 QGraphicsItem::itemChange ().

QGraphicsLayout *QGraphicsWidget:: layout () const

Returns this widget's layout, or 0 if no layout is currently managing this widget.

注意: getter 函數對於特性 layout .

另請參閱 setLayout ().

[virtual protected] void QGraphicsWidget:: moveEvent ( QGraphicsSceneMoveEvent * event )

此事件處理程序用於 GraphicsSceneMove events, 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's ancestors does not affect the item's local position.

You can reimplement this event handler to detect when your widget has moved. Calling QEvent::accept () 或 QEvent::ignore () 在 event 不起作用。

另請參閱 ItemPositionChange and ItemPositionHasChanged .

[虛擬] void QGraphicsWidget:: paint ( QPainter * painter , const QStyleOptionGraphicsItem * option , QWidget * widget = Q_NULLPTR)

重實現自 QGraphicsItem::paint ().

[虛擬] void QGraphicsWidget:: paintWindowFrame ( QPainter * painter , const QStyleOptionGraphicsItem * option , QWidget * widget = Q_NULLPTR)

此虛函數被調用由 QGraphicsScene to draw the window frame for windows using painter , option ,和 widget , in local coordinates. The base implementation uses the current style to render the frame and title bar.

可以重實現此函數在子類 QGraphicsWidget to provide custom rendering of the widget's window frame.

另請參閱 QGraphicsItem::paint ().

[virtual protected] void 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.

QRectF QGraphicsWidget:: rect () const

Returns the item's local rect as a QRectF . This function is equivalent to QRectF (QPointF(), size ()).

另請參閱 setGeometry () 和 resize ().

void QGraphicsWidget:: releaseShortcut ( int id )

刪除快捷方式采用給定 id 從 Qt 的快捷方式係統。Widget 將不再接收 QEvent::Shortcut 事件對於快捷方式鍵序列 (除非它有具有相同鍵序列的其它快捷方式)。

警告: 通常應該不需要使用此函數,因為 Qt 的快捷方式係統會自動移除快捷方式,當它們的父級 Widget 被銷毀時。最好使用 QAction or QShortcut 處理快捷方式,因為它們比此低級函數更易於使用。另請注意,此操作很昂貴。

該函數在 Qt 4.5 引入。

另請參閱 grabShortcut (), setShortcutEnabled (),和 QWidget::releaseShortcut ().

void QGraphicsWidget:: removeAction ( QAction * action )

移除動作 action 從此 Widget 的動作列錶。

該函數在 Qt 4.5 引入。

另請參閱 insertAction (), actions (), insertAction (),和 QWidget::removeAction ().

void QGraphicsWidget:: resize ( qreal w , qreal h )

這是重載函數。

Constructs a resize with the given width ( w ) 和 height ( h ). This convenience function is equivalent to calling resize( QSizeF (w, h)).

注意: setter 函數對於特性 size .

另請參閱 setGeometry () 和 setTransform ().

[virtual protected] void QGraphicsWidget:: resizeEvent ( QGraphicsSceneResizeEvent * event )

此事件處理程序用於 GraphicsSceneResize events, is delivered after the widget has been resized (i.e., its local size has changed). event contains 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's local size.

You can reimplement this event handler to detect when your widget has been resized. Calling QEvent::accept () 或 QEvent::ignore () 在 event 不起作用。

另請參閱 geometry () 和 setGeometry ().

[virtual protected] bool QGraphicsWidget:: sceneEvent ( QEvent * event )

重實現自 QGraphicsItem::sceneEvent ().

QGraphicsWidget 's implementation of sceneEvent() simply passes event to QGraphicsWidget::event (). You can handle all events for your widget in event () or in any of the convenience functions; you should not have to reimplement this function in a subclass of QGraphicsWidget .

另請參閱 QGraphicsItem::sceneEvent ().

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

on is true, this function enables attribute ;否則 attribute 被禁用。

See the class documentation for QGraphicsWidget for a complete list of which attributes are supported, and what they are for.

另請參閱 testAttribute () 和 QWidget::setAttribute ().

void QGraphicsWidget:: setContentsMargins ( qreal left , qreal top , qreal right , qreal bottom )

Sets the widget's contents margins to left , top , right and bottom .

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's contents margins will always trigger an update (), and any assigned layout will be activated automatically. The widget will then receive a ContentsRectChange 事件。

另請參閱 getContentsMargins () 和 setGeometry ().

void QGraphicsWidget:: setGeometry ( qreal x , qreal y , qreal w , qreal h )

此方便函數相當於調用 setGeometry ( QRectF ( x , y , w , h )).

注意: setter 函數對於特性 geometry .

另請參閱 geometry () 和 resize ().

void QGraphicsWidget:: setLayout ( QGraphicsLayout * layout )

Sets the layout for this widget to layout . Any existing layout manager is deleted before the new layout is assigned. If layout is 0, the widget is left without a layout. Existing subwidgets' geometries will remain unaffected.

All widgets that are currently managed by layout or 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's geometry () and contentsMargins(). Children who are not explicitly managed by layout remain unaffected by the layout after it has been assigned to this widget.

QGraphicsWidget 擁有所有權對於 layout .

注意: setter 函數對於特性 layout .

另請參閱 layout (), QGraphicsLinearLayout::addItem (),和 QGraphicsLayout::invalidate ().

void QGraphicsWidget:: setShortcutAutoRepeat ( int id , bool enabled = true)

enabled 為 true,快捷方式的自動重復采用給定 id 被啓用;否則被禁用。

該函數在 Qt 4.5 引入。

另請參閱 grabShortcut (), releaseShortcut (),和 QWidget::setShortcutAutoRepeat ().

void QGraphicsWidget:: setShortcutEnabled ( int id , bool enabled = true)

enabled 為 True,快捷方式采用給定 id 被啓用;否則快捷方式被禁用。

警告: 應該通常不需要使用此函數,因為 Qt 的快捷方式係統會自動啓用/禁用快捷方式當 Widget 變為隱藏/可見並獲得 (或失去) 聚焦時。最好使用 QAction or QShortcut 處理快捷方式,因為它們比此低級函數更易於使用。

該函數在 Qt 4.5 引入。

另請參閱 grabShortcut (), releaseShortcut (),和 QWidget::setShortcutEnabled ().

void QGraphicsWidget:: setStyle ( QStyle * style )

將 Widget 樣式設為 style . QGraphicsWidget does not 擁有所有權對於 style .

若未賦值樣式,或 style is 0, the widget will use QGraphicsScene::style () 若有設置。否則 Widget 將使用 QApplication::style ().

此函數設置 Qt::WA_SetStyle 屬性若 style is not 0; otherwise it clears the attribute.

另請參閱 style ().

[static] void QGraphicsWidget:: setTabOrder ( QGraphicsWidget * first , QGraphicsWidget * second )

移動 second widget around the ring of focus widgets so that keyboard focus moves from the first widget to the second widget when the Tab key is pressed.

注意,由於選項卡次序對於 second 小部件已改變,應排序鏈像這樣:

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 像這樣:

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

first is 0, this indicates that second should 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). If second is 0, this indicates that first should be the first widget to gain focus if the scene gained BackTab focus.

By default, tab order is defined implicitly using widget creation order.

另請參閱 focusPolicy and Widget 鍵盤聚焦 .

void QGraphicsWidget:: setWindowFrameMargins ( qreal left , qreal top , qreal right , qreal bottom )

Sets the widget's window frame margins to left , top , right and bottom . 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.

另請參閱 unsetWindowFrameMargins (), getWindowFrameMargins (),和 windowFrameRect ().

[虛擬] QPainterPath QGraphicsWidget:: shape () const

重實現自 QGraphicsItem::shape ().

[virtual protected] void QGraphicsWidget:: showEvent ( QShowEvent * event )

此事件處理程序用於 Show events, 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 QEvent::accept () 或 QEvent::ignore () 在 event 不起作用。

另請參閱 hideEvent (), QWidget::showEvent (),和 ItemVisibleChange .

[virtual protected] QSizeF QGraphicsWidget:: sizeHint ( Qt::SizeHint which , const QSizeF & constraint = QSizeF()) const

重實現自 QGraphicsLayoutItem::sizeHint ().

QStyle *QGraphicsWidget:: style () const

Returns a pointer to the widget's style. If this widget does not have any explicitly assigned style, the scene's style is returned instead. In turn, if the scene does not have any assigned style, this function returns QApplication::style ().

另請參閱 setStyle ().

bool QGraphicsWidget:: testAttribute ( Qt::WidgetAttribute attribute ) const

返迴 true if attribute is enabled for this widget; otherwise, returns false .

另請參閱 setAttribute ().

[虛擬] int QGraphicsWidget:: type () const

重實現自 QGraphicsItem::type ().

[virtual protected] void QGraphicsWidget:: ungrabKeyboardEvent ( QEvent * event )

此事件處理程序用於 event ,可以在子類中重實現以接收通知為 QEvent::UngrabKeyboard 事件。

另請參閱 ungrabKeyboard () 和 ungrabMouse ().

[virtual protected] void QGraphicsWidget:: ungrabMouseEvent ( QEvent * event )

此事件處理程序用於 event ,可以在子類中重實現以接收通知為 QEvent::UngrabMouse 事件。

另請參閱 ungrabMouse () 和 ungrabKeyboard ().

void QGraphicsWidget:: unsetWindowFrameMargins ()

Resets the window frame margins to the default value, provided by the style.

另請參閱 setWindowFrameMargins (), getWindowFrameMargins (),和 windowFrameRect ().

[virtual protected] void QGraphicsWidget:: updateGeometry ()

重實現自 QGraphicsLayoutItem::updateGeometry ().

If this widget is currently managed by a layout, this function notifies the layout that the widget's size hints have changed and the layout may need to resize and reposition the widget accordingly.

Call this function if the widget's sizeHint () has changed.

另請參閱 QGraphicsLayout::invalidate ().

[virtual protected] bool QGraphicsWidget:: windowFrameEvent ( QEvent * event )

此事件處理程序用於 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.

返迴 true if event 已被識彆並處理;否則,返迴 false .

另請參閱 event ().

QRectF QGraphicsWidget:: windowFrameGeometry () const

Returns the widget's geometry in parent coordinates including any window frame.

另請參閱 windowFrameRect (), getWindowFrameMargins (),和 setWindowFrameMargins ().

QRectF QGraphicsWidget:: windowFrameRect () const

Returns the widget's local rect including any window frame.

另請參閱 windowFrameGeometry (), getWindowFrameMargins (),和 setWindowFrameMargins ().

[virtual protected] Qt::WindowFrameSection QGraphicsWidget:: windowFrameSectionAt (const QPointF & pos ) const

Returns the window frame section at position pos ,或 Qt::NoSection if there is no window frame section at this position.

This function is used in QGraphicsWidget 's 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 Qt::NoSection for all sections except Qt::BottomRightSection .

該函數在 Qt 4.4 引入。

另請參閱 windowFrameEvent (), paintWindowFrame (),和 windowFrameGeometry ().

Qt::WindowType QGraphicsWidget:: windowType () const

Returns the widgets window type.

另請參閱 windowFlags (), isWindow (),和 isPanel ().