Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QGraphicsWidget Class

TheQGraphicsWidget class is the base class for all widget items in aQGraphicsScene.More...

Header:#include <QGraphicsWidget>
Since: Qt 4.4
Inherits:QGraphicsObject andQGraphicsLayoutItem
Inherited By:

QGraphicsProxyWidget andQGraphicsWebView

Properties

Public Functions

QGraphicsWidget(QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0)
~QGraphicsWidget()
QList<QAction *>actions() const
voidaddAction(QAction * action)
voidaddActions(QList<QAction *> actions)
voidadjustSize()
boolautoFillBackground() const
Qt::FocusPolicyfocusPolicy() const
QGraphicsWidget *focusWidget() const
QFontfont() const
voidgetWindowFrameMargins(qreal * left, qreal * top, qreal * right, qreal * bottom) const
intgrabShortcut(const QKeySequence & sequence, Qt::ShortcutContext context = Qt::WindowShortcut)
voidinsertAction(QAction * before, QAction * action)
voidinsertActions(QAction * before, QList<QAction *> actions)
boolisActiveWindow() const
QGraphicsLayout *layout() const
Qt::LayoutDirectionlayoutDirection() const
virtual voidpaintWindowFrame(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0)
QPalettepalette() const
QRectFrect() const
voidreleaseShortcut(int id)
voidremoveAction(QAction * action)
voidresize(const QSizeF & size)
voidresize(qreal w, qreal h)
voidsetAttribute(Qt::WidgetAttribute attribute, bool on = true)
voidsetAutoFillBackground(bool enabled)
voidsetContentsMargins(qreal left, qreal top, qreal right, qreal bottom)
voidsetFocusPolicy(Qt::FocusPolicy policy)
voidsetFont(const QFont & font)
voidsetGeometry(qreal x, qreal y, qreal w, qreal h)
voidsetLayout(QGraphicsLayout * layout)
voidsetLayoutDirection(Qt::LayoutDirection direction)
voidsetPalette(const QPalette & palette)
voidsetShortcutAutoRepeat(int id, bool enabled = true)
voidsetShortcutEnabled(int id, bool enabled = true)
voidsetStyle(QStyle * style)
voidsetWindowFlags(Qt::WindowFlags wFlags)
voidsetWindowFrameMargins(qreal left, qreal top, qreal right, qreal bottom)
voidsetWindowTitle(const QString & title)
QSizeFsize() const
QStyle *style() const
booltestAttribute(Qt::WidgetAttribute attribute) const
voidunsetLayoutDirection()
voidunsetWindowFrameMargins()
Qt::WindowFlagswindowFlags() const
QRectFwindowFrameGeometry() const
QRectFwindowFrameRect() const
QStringwindowTitle() const
Qt::WindowTypewindowType() const

Reimplemented Public Functions

virtual QRectFboundingRect() const
virtual voidgetContentsMargins(qreal * left, qreal * top, qreal * right, qreal * bottom) const
virtual voidpaint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0)
virtual voidsetGeometry(const QRectF & rect)
virtual QPainterPathshape() const
virtual inttype() const

Public Slots

boolclose()
  • 1 public slot inherited fromQObject

Signals

Static Public Members

voidsetTabOrder(QGraphicsWidget * first, QGraphicsWidget * second)

Protected Functions

virtual voidchangeEvent(QEvent * event)
virtual voidcloseEvent(QCloseEvent * event)
virtual boolfocusNextPrevChild(bool next)
virtual voidgrabKeyboardEvent(QEvent * event)
virtual voidgrabMouseEvent(QEvent * event)
virtual voidhideEvent(QHideEvent * event)
virtual voidinitStyleOption(QStyleOption * option) const
virtual voidmoveEvent(QGraphicsSceneMoveEvent * event)
virtual voidpolishEvent()
virtual voidresizeEvent(QGraphicsSceneResizeEvent * event)
virtual voidshowEvent(QShowEvent * event)
virtual voidungrabKeyboardEvent(QEvent * event)
virtual voidungrabMouseEvent(QEvent * event)
virtual boolwindowFrameEvent(QEvent * event)
virtual Qt::WindowFrameSectionwindowFrameSectionAt(const QPointF & pos) const

Reimplemented Protected Functions

virtual boolevent(QEvent * event)
virtual voidfocusInEvent(QFocusEvent * event)
virtual voidfocusOutEvent(QFocusEvent * event)
virtual voidhoverLeaveEvent(QGraphicsSceneHoverEvent * event)
virtual voidhoverMoveEvent(QGraphicsSceneHoverEvent * event)
virtual QVariantitemChange(GraphicsItemChange change, const QVariant & value)
virtual boolsceneEvent(QEvent * event)
virtual QSizeFsizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const
virtual voidupdateGeometry()

Additional Inherited Members

Detailed Description

TheQGraphicsWidget class is the base class for all widget items in aQGraphicsScene.

QGraphicsWidget is an extended base item that provides extra functionality overQGraphicsItem. It is similar toQWidget in many ways:

UnlikeQGraphicsItem,QGraphicsWidget is not an abstract class; you can create instances of aQGraphicsWidget 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.

SinceQGraphicsWidget resemblesQWidget and has similar API, it is easier to port a widget fromQWidget toQGraphicsWidget, instead ofQGraphicsItem.

Note:QWidget-based widgets can be directly embedded into aQGraphicsScene usingQGraphicsProxyWidget.

Noticeable differences betweenQGraphicsWidget andQWidget are:

QGraphicsWidgetQWidget
Coordinates and geometry are defined with qreals (doubles or floats, depending on the platform).QWidget uses integer geometry (QPoint,QRect).
The widget is already visible by default; you do not have to callshow() to display the widget.QWidget is hidden by default until you callshow().
A subset of widget attributes are supported.All widget attributes are supported.
A top-level item's style defaults toQGraphicsScene::styleA top-level widget's style defaults toQApplication::style
Graphics View provides a custom drag and drop framework, different fromQWidget.Standard drag and drop framework.
Widget items do not support modality.Full modality support.

QGraphicsWidget supports a subset of Qt's widget attributes, (Qt::WidgetAttribute), as shown in the table below. Any attributes not listed in this table are unsupported, or otherwise unused.

Widget AttributeUsage
Qt::WA_SetLayoutDirectionSet bysetLayoutDirection(), 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.
Qt::WA_RightToLeftToggled bysetLayoutDirection(). Inherited from the parent/scene. If set, the widget's layout will order horizontally arranged widgets from right to left.
Qt::WA_SetStyleSet and cleared bysetStyle(). 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_ResizedSet bysetGeometry() andresize().
Qt::WA_SetPaletteSet bysetPalette().
Qt::WA_SetFontSet bysetFont().
Qt::WA_WindowPropagationEnables propagation to window widgets.

AlthoughQGraphicsWidget inherits from bothQObject andQGraphicsItem, 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:TheQObject::parent() should always return 0 for QGraphicsWidgets, but this policy is not strictly defined.

See alsoQGraphicsProxyWidget,QGraphicsItem, andWidgets and Layouts.

Property Documentation

autoFillBackground :bool

This property holds whether the widget background is filled automatically.

If enabled, this property will cause Qt to fill the background of the widget before invoking thepaint() method. The color used is defined by theQPalette::Window color role from the widget'spalette.

In addition, Windows are always filled withQPalette::Window, unless the WA_OpaquePaintEvent or WA_NoSystemBackground attributes are set.

By default, this property is false.

This property was introduced in Qt 4.7.

Access functions:

boolautoFillBackground() const
voidsetAutoFillBackground(bool enabled)

See alsoQt::WA_OpaquePaintEvent andQt::WA_NoSystemBackground.

focusPolicy :Qt::FocusPolicy

This property holds the way the widget accepts keyboard focus.

The focus policy isQt::TabFocus if the widget accepts keyboard focus by tabbing,Qt::ClickFocus if the widget accepts focus by clicking,Qt::StrongFocus if it accepts both, andQt::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, theQLineEdit constructor calls setFocusPolicy(Qt::StrongFocus).

If you enable a focus policy (i.e., notQt::NoFocus),QGraphicsWidget will automatically enable theItemIsFocusable flag. SettingQt::NoFocus on a widget will clear theItemIsFocusable flag. If the widget currently has keyboard focus, the widget will automatically lose focus.

Access functions:

Qt::FocusPolicyfocusPolicy() const
voidsetFocusPolicy(Qt::FocusPolicy policy)

See alsofocusInEvent(),focusOutEvent(),keyPressEvent(),keyReleaseEvent(), andenabled.

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 aFontChange event and notifies all its descendants so that they can resolve their fonts as well.

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

Access functions:

QFontfont() const
voidsetFont(const QFont & font)

See alsoQApplication::font(),QGraphicsScene::font, andQFont::resolve().

geometry :QRectF

This property holds the geometry of the widget.

Sets the item's geometry torect. 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.

Access functions:

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

Notifier signal:

See alsogeometry() andresize().

layout :QGraphicsLayout *

This property holds the layout of the widget.

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

QGraphicsWidget takes ownership oflayout.

All widgets that are currently managed bylayout 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'sgeometry() and contentsMargins(). Children who are not explicitly managed bylayout 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.

Access functions:

QGraphicsLayout *layout() const
voidsetLayout(QGraphicsLayout * layout)

layoutDirection :Qt::LayoutDirection

This property holds the layout direction for this widget.

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

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. WithQt::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 aLayoutDirectionChange event, and then propagate the new layout direction to all its descendants.

Access functions:

Qt::LayoutDirectionlayoutDirection() const
voidsetLayoutDirection(Qt::LayoutDirection direction)
voidunsetLayoutDirection()

See alsoQWidget::layoutDirection andQApplication::layoutDirection.

maximumSize : constQSizeF

This property holds the maximum size of the widget.

See alsosetMaximumSize(),maximumSize(),minimumSize, andpreferredSize.

minimumSize : constQSizeF

This property holds the minimum size of the widget.

See alsosetMinimumSize(),minimumSize(),preferredSize, andmaximumSize.

palette :QPalette

This property holds the widget's palette.

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 aPaletteChange event, and notifies all its descendants so they can resolve their palettes as well.

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

Access functions:

QPalettepalette() const
voidsetPalette(const QPalette & palette)

See alsoQApplication::palette(),QGraphicsScene::palette, andQPalette::resolve().

preferredSize : constQSizeF

This property holds the preferred size of the widget.

See alsosetPreferredSize(),preferredSize(),minimumSize, andmaximumSize.

size :QSizeF

This property holds the size of the widget.

Calling resize() resizes the widget to asize bounded byminimumSize() andmaximumSize(). 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 aGraphicsSceneResize 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.

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

Access functions:

QSizeFsize() const
voidresize(const QSizeF & size)
voidresize(qreal w, qreal h)

Notifier signal:

voidgeometryChanged()

See alsosetGeometry(),QGraphicsSceneResizeEvent, andQGraphicsLayout.

sizePolicy : constQSizePolicy

This property holds the size policy for the widget.

See alsosizePolicy(),setSizePolicy(), andQWidget::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 theQt::Window flag, theItemIsPanel flag will be set automatically. If you clear theQt::Window flag, theItemIsPanel flag is also cleared. Note that theItemIsPanel flag can be set independently ofQt::Window.

Access functions:

Qt::WindowFlagswindowFlags() const
voidsetWindowFlags(Qt::WindowFlags wFlags)

See alsoisWindow() andisPanel().

windowTitle :QString

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.

Access functions:

QStringwindowTitle() const
voidsetWindowTitle(const QString & title)

Member Function Documentation

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

Constructs aQGraphicsWidget instance. The optionalparent argument is passed toQGraphicsItem's constructor. The optionalwFlags argument specifies the widget's window flags (e.g., whether the widget should be a window, a tool, a popup, etc).

QGraphicsWidget::~QGraphicsWidget()

Destroys theQGraphicsWidget instance.

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

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

This function was introduced in Qt 4.5.

See alsoinsertAction(),removeAction(),QWidget::actions(),QAction::associatedWidgets(), andQAction::associatedGraphicsWidgets().

void QGraphicsWidget::addAction(QAction * action)

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

All QGraphicsWidgets have a list ofQActions, however they can be represented graphically in many different ways. The default use of theQAction list (as returned byactions()) is to create a contextQMenu.

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

This function was introduced in Qt 4.5.

See alsoremoveAction(),insertAction(),actions(), andQWidget::addAction().

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

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

This function was introduced in Qt 4.5.

See alsoremoveAction(),QMenu,addAction(), andQWidget::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.

See alsoeffectiveSizeHint() andQt::MinimumSize.

[virtual]QRectF QGraphicsWidget::boundingRect() const

Reimplemented fromQGraphicsItem::boundingRect().

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

This event handler can be reimplemented to handle state changes.

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

Change events include:QEvent::ActivationChange,QEvent::EnabledChange,QEvent::FontChange,QEvent::StyleChange,QEvent::PaletteChange,QEvent::ParentChange,QEvent::LayoutDirectionChange, andQEvent::ContentsRectChange.

[slot]bool QGraphicsWidget::close()

Call this function to close the widget.

Returns true if the widget was closed; otherwise returns false. This slot will first send aQCloseEvent to 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 theQt::WA_DeleteOnClose attribute set it will be deleted.

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

This event handler, forevent, can be reimplemented in a subclass to receive widget close events. The default implementation accepts the event.

See alsoclose() andQCloseEvent.

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

Reimplemented fromQObject::event().

Handles theevent.QGraphicsWidget handles the following events:

EventUsage
PolishDelivered to the widget some time after it has been shown.
GraphicsSceneMoveDelivered to the widget after its local position has changed.
GraphicsSceneResizeDelivered to the widget after its size has changed.
ShowDelivered to the widget before it has been shown.
HideDelivered to the widget after it has been hidden.
PaletteChangeDelivered to the widget after its palette has changed.
FontChangeDelivered to the widget after its font has changed.
EnabledChangeDelivered to the widget after its enabled state has changed.
StyleChangeDelivered to the widget after its style has changed.
LayoutDirectionChangeDelivered to the widget after its layout direction has changed.
ContentsRectChangeDelivered to the widget after its contents margins/ contents rect has changed.

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

Reimplemented fromQGraphicsItem::focusInEvent().

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

Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget; returns false otherwise. Ifnext is true, this function searches forward; ifnext is 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 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.

See alsofocusPolicy().

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

Reimplemented fromQGraphicsItem::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.

See alsoQGraphicsItem::focusItem() andQWidget::focusWidget().

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

Reimplemented fromQGraphicsLayoutItem::getContentsMargins().

Gets the widget's contents margins. The margins are stored inleft,top,right andbottom, as pointers to qreals. Each argument can beomitted by passing 0.

See alsosetContentsMargins().

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

Gets the widget's window frame margins. The margins are stored inleft,top,right andbottom as pointers to qreals. Each argument can beomitted by passing 0.

See alsosetWindowFrameMargins() andwindowFrameRect().

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

This event handler, forevent, can be reimplemented in a subclass to receive notifications forQEvent::GrabKeyboard events.

See alsograbKeyboard() andgrabMouse().

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

This event handler, forevent, can be reimplemented in a subclass to receive notifications forQEvent::GrabMouse events.

See alsograbMouse() andgrabKeyboard().

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

Adds a shortcut to Qt's shortcut system that watches for the given keysequence in the givencontext. If thecontext isQt::ApplicationShortcut, the shortcut applies to the application as a whole. Otherwise, it is either local to this widget,Qt::WidgetShortcut, or to the window itself,Qt::WindowShortcut. 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 keysequence has been grabbed by several widgets, when the keysequence occurs aQEvent::Shortcut event is sent to all the widgets to which it applies in a non-deterministic order, but with the ``ambiguous'' flag set to true.

Warning: You should not normally need to use this function; instead createQActions 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. BothQAction andQShortcut handle all the event filtering for you, and provide signals which are triggered when the user triggers the key sequence, so are much easier to use than this low-level function.

This function was introduced in Qt 4.5.

See alsoreleaseShortcut(),setShortcutEnabled(), andQWidget::grabShortcut().

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

This event handler, forHide 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. CallingQEvent::accept() orQEvent::ignore() onevent has no effect.

See alsoshowEvent(),QWidget::hideEvent(), andItemVisibleChange.

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

Reimplemented fromQGraphicsItem::hoverLeaveEvent().

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

Reimplemented fromQGraphicsItem::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 inoption. The default implementation populatesoption with the following properties.

Style Option PropertyValue
state &QStyle::State_EnabledCorresponds toQGraphicsItem::isEnabled().
state &QStyle::State_HasFocusCorresponds toQGraphicsItem::hasFocus().
state &QStyle::State_MouseOverCorresponds toQGraphicsItem::isUnderMouse().
directionCorresponds toQGraphicsWidget::layoutDirection().
rectCorresponds toQGraphicsWidget::rect().toRect().
paletteCorresponds toQGraphicsWidget::palette().
fontMetricsCorresponds toQFontMetrics(QGraphicsWidget::font()).

Subclasses ofQGraphicsWidget should call the base implementation, and then test the type ofoption usingqstyleoption_cast<>() or testQStyleOption::Type before storing widget-specific options.

For example:

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

See alsoQStyleOption::initFrom().

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

Inserts the actionaction to this widget's list of actions, before the actionbefore. It appends the action ifbefore is 0 orbefore is not a valid action for this widget.

AQGraphicsWidget should only have one of each action.

This function was introduced in Qt 4.5.

See alsoremoveAction(),addAction(),QMenu,actions(), andQWidget::insertActions().

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

Inserts the actionsactions to this widget's list of actions, before the actionbefore. It appends the action ifbefore is 0 orbefore is not a valid action for this widget.

AQGraphicsWidget can have at most one of each action.

This function was introduced in Qt 4.5.

See alsoremoveAction(),QMenu,insertAction(), andQWidget::insertActions().

bool QGraphicsWidget::isActiveWindow() const

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

See alsoQGraphicsScene::activeWindow(),QGraphicsScene::setActiveWindow(), andisActive().

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

Reimplemented fromQGraphicsItem::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, andvalue is the new value.

For example,QGraphicsWidget usesItemVisibleChange to deliverShow andHide events,ItemPositionHasChanged to deliverMove events, andItemParentChange both to deliverParentChange events, and for managing the focus chain.

QGraphicsWidget enables theItemSendsGeometryChanges flag by default in order to track position changes.

See alsoQGraphicsItem::itemChange().

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

This event handler, forGraphicsSceneMove 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. CallingsetTransform() 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. CallingQEvent::accept() orQEvent::ignore() onevent has no effect.

See alsoItemPositionChange andItemPositionHasChanged.

[virtual]void QGraphicsWidget::paint(QPainter * painter, constQStyleOptionGraphicsItem * option,QWidget * widget = 0)

Reimplemented fromQGraphicsItem::paint().

[virtual]void QGraphicsWidget::paintWindowFrame(QPainter * painter, constQStyleOptionGraphicsItem * option,QWidget * widget = 0)

This virtual function is called byQGraphicsScene to 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 ofQGraphicsWidget to provide custom rendering of the widget's window frame.

See alsoQGraphicsItem::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 aQRectF. This function is equivalent toQRectF(QPointF(),size()).

See alsosetGeometry() andresize().

void QGraphicsWidget::releaseShortcut(int id)

Removes the shortcut with the givenid from Qt's shortcut system. The widget will no longer receiveQEvent::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 useQAction orQShortcut to handle shortcuts, since they are easier to use than this low-level function. Note also that this is an expensive operation.

This function was introduced in Qt 4.5.

See alsograbShortcut(),setShortcutEnabled(), andQWidget::releaseShortcut().

void QGraphicsWidget::removeAction(QAction * action)

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

This function was introduced in Qt 4.5.

See alsoinsertAction(),actions(),insertAction(), andQWidget::removeAction().

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

This event handler, forGraphicsSceneResize 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; callingsetTransform() 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. CallingQEvent::accept() orQEvent::ignore() onevent has no effect.

See alsogeometry() andsetGeometry().

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

Reimplemented fromQGraphicsItem::sceneEvent().

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

See alsoQGraphicsItem::sceneEvent().

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

Ifon is true, this function enablesattribute; otherwiseattribute is disabled.

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

See alsotestAttribute() andQWidget::setAttribute().

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

Sets the widget's contents margins toleft,top,right andbottom.

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 anupdate(), and any assigned layout will be activated automatically. The widget will then receive aContentsRectChange event.

See alsogetContentsMargins() andsetGeometry().

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

Ifenabled is true, auto repeat of the shortcut with the givenid is enabled; otherwise it is disabled.

This function was introduced in Qt 4.5.

See alsograbShortcut(),releaseShortcut(), andQWidget::setShortcutAutoRepeat().

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

Ifenabled is true, the shortcut with the givenid is enabled; otherwise the shortcut is disabled.

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

This function was introduced in Qt 4.5.

See alsograbShortcut(),releaseShortcut(), andQWidget::setShortcutEnabled().

void QGraphicsWidget::setStyle(QStyle * style)

Sets the widget's style tostyle.QGraphicsWidget doesnot take ownership ofstyle.

If no style is assigned, orstyle is 0, the widget will useQGraphicsScene::style() (if this has been set). Otherwise the widget will useQApplication::style().

This function sets theQt::WA_SetStyle attribute ifstyle is not 0; otherwise it clears the attribute.

See alsostyle().

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

Moves thesecond widget around the ring of focus widgets so that keyboard focus moves from thefirst widget to thesecond widget when the Tab key is pressed.

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

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

not like this:

// WRONGsetTabOrder(c, d);// c to dsetTabOrder(a, b);// a to b AND c to dsetTabOrder(b, c);// a to b to c, but not c to d

Iffirst is 0, this indicates thatsecond 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). Ifsecond is 0, this indicates thatfirst 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.

See alsofocusPolicy andKeyboard Focus.

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

Sets the widget's window frame margins toleft,top,right andbottom. 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.

See alsounsetWindowFrameMargins(),getWindowFrameMargins(), andwindowFrameRect().

[virtual]QPainterPath QGraphicsWidget::shape() const

Reimplemented fromQGraphicsItem::shape().

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

This event handler, forShow 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. CallingQEvent::accept() orQEvent::ignore() onevent has no effect.

See alsohideEvent(),QWidget::showEvent(), andItemVisibleChange.

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

Reimplemented fromQGraphicsLayoutItem::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 returnsQApplication::style().

See alsosetStyle().

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

Returns true ifattribute is enabled for this widget; otherwise, returns false.

See alsosetAttribute().

[virtual]int QGraphicsWidget::type() const

Reimplemented fromQGraphicsItem::type().

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

This event handler, forevent, can be reimplemented in a subclass to receive notifications forQEvent::UngrabKeyboard events.

See alsoungrabKeyboard() andungrabMouse().

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

This event handler, forevent, can be reimplemented in a subclass to receive notifications forQEvent::UngrabMouse events.

See alsoungrabMouse() andungrabKeyboard().

void QGraphicsWidget::unsetWindowFrameMargins()

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

See alsosetWindowFrameMargins(),getWindowFrameMargins(), andwindowFrameRect().

[virtual protected]void QGraphicsWidget::updateGeometry()

Reimplemented fromQGraphicsLayoutItem::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'ssizeHint() has changed.

See alsoQGraphicsLayout::invalidate().

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

This event handler, forevent, 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 ofQGraphicsWidget to provide your own custom window frame interaction support.

Returns true ifevent has been recognized and processed; otherwise, returns false.

See alsoevent().

QRectF QGraphicsWidget::windowFrameGeometry() const

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

See alsowindowFrameRect(),getWindowFrameMargins(), andsetWindowFrameMargins().

QRectF QGraphicsWidget::windowFrameRect() const

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

See alsowindowFrameGeometry(),getWindowFrameMargins(), andsetWindowFrameMargins().

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

Returns the window frame section at positionpos, orQt::NoSection if there is no window frame section at this position.

This function is used inQGraphicsWidget'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 returnQt::NoSection for all sections exceptQt::BottomRightSection.

This function was introduced in Qt 4.4.

See alsowindowFrameEvent(),paintWindowFrame(), andwindowFrameGeometry().

Qt::WindowType QGraphicsWidget::windowType() const

Returns the widgets window type.

See alsowindowFlags(),isWindow(), andisPanel().

© 2016 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 theGNU 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.


[8]ページ先頭

©2009-2025 Movatter.jp