com.trolltech.qt.gui
Class QGraphicsProxyWidget

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.gui.QGraphicsWidget
                  extended by com.trolltech.qt.gui.QGraphicsProxyWidget
All Implemented Interfaces:
QGraphicsItemInterface, QGraphicsLayoutItemInterface, QtJambiInterface

public class QGraphicsProxyWidget
extends QGraphicsWidget

The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene. QGraphicsProxyWidget embeds any QWidget-based widget, for example, a QPushButton, QFontComboBox, or even QFileDialog, into QGraphicsScene. It forwards events between the two objects and translates between QWidget's integer-based geometry and QGraphicsWidget's qreal-based geometry. QGraphicsProxyWidget supports all core features of QWidget, including tab focus, keyboard input, Drag & Drop, and popups. You can also embed complex widgets, e.g., widgets with subwidgets.

Example:

The following code example is written in c++.

    int main(int argc, char **argv)
    {
        QApplication app(argc, argv);

        QTabWidget *tabWidget = new QTabWidget;

        QGraphicsScene scene;
        QGraphicsProxyWidget *proxy = scene.addWidget(tabWidget);

        QGraphicsView view(&scene);
        view.show();

        return app.exec();
    }
QGraphicsProxyWidget takes care of automatically embedding popup children of embedded widgets through creating a child proxy for each popup. This means that when an embedded QComboBox shows its popup list, a new QGraphicsProxyWidget is created automatically, embedding the popup, and positioning it correctly.

Embedding a Widget with QGraphicsProxyWidget

There are two ways to embed a widget using
QGraphicsProxyWidget. The most common way is to pass a widget pointer to QGraphicsScene::addWidget() together with any relevant Qt::WindowFlags. This function returns a pointer to a QGraphicsProxyWidget. You can then choose to reparent or position either the proxy, or the embedded widget itself.

For example, in the code snippet below, we embed a group box into the proxy:

The following code example is written in c++.

    QGroupBox *groupBox = new QGroupBox("Contact Details");
    QLabel *numberLabel = new QLabel("Telephone number");
    QLineEdit *numberEdit = new QLineEdit;

    QFormLayout *layout = new QFormLayout;
    layout->addRow(numberLabel, numberEdit);
    groupBox->setLayout(layout);

    QGraphicsScene scene;
    QGraphicsProxyWidget *proxy = scene.addWidget(groupBox);

    QGraphicsView view(&scene);
    view.show();
The image below is the output obtained with its contents margin and contents rect labeled.

Alternatively, you can start by creating a new QGraphicsProxyWidget item, and then call setWidget() to embed a QWidget later. The widget() function returns a pointer to the embedded widget. QGraphicsProxyWidget shares ownership with QWidget, so if either of the two widgets are destroyed, the other widget will be automatically destroyed as well.

Synchronizing Widget States

QGraphicsProxyWidget keeps its state in sync with the embedded widget. For example, if the proxy is hidden or disabled, the embedded widget will be hidden or disabled as well, and vice versa. When the widget is embedded by calling addWidget(), QGraphicsProxyWidget copies the state from the widget into the proxy, and after that, the two will stay synchronized where possible. By default, when you embed a widget into a proxy, both the widget and the proxy will be visible because a QGraphicsWidget is visible when created (you do not have to call show()). If you explicitly hide the embedded widget, the proxy will also become invisible.

Example:

The following code example is written in c++.

        QGraphicsScene scene;

        QLineEdit *edit = new QLineEdit;
        QGraphicsProxyWidget *proxy = scene.addWidget(edit);

        edit->isVisible();  // returns true
        proxy->isVisible(); // also returns true

        edit->hide();

        edit->isVisible();  // returns false
        proxy->isVisible(); // also returns false
    }
QGraphicsProxyWidget maintains symmetry for the following states:
QWidget state QGraphicsProxyWidget state Notes
QWidget::enabled QGraphicsProxyWidget::enabled
QWidget::visible QGraphicsProxyWidget::visible The explicit state is also symmetric.
QWidget::geometry QGraphicsProxyWidget::geometry Geometry is only guaranteed to be symmetric while the embedded widget is visible.
QWidget::layoutDirection QGraphicsProxyWidget::layoutDirection
QWidget::style QGraphicsProxyWidget::style
QWidget::palette QGraphicsProxyWidget::palette
QWidget::font QGraphicsProxyWidget::font
QWidget::cursor QGraphicsProxyWidget::cursor The embedded widget overrides the proxy widget cursor. The proxy cursor changes depending on which embedded subwidget is currently under the mouse.
QWidget::sizeHint() QGraphicsProxyWidget::sizeHint() All size hint functionality from the embedded widget is forwarded by the proxy.
QWidget::getContentsMargins() QGraphicsProxyWidget::getContentsMargins() Updated once by setWidget().
QWidget::windowTitle QGraphicsProxyWidget::windowTitle Updated once by setWidget().
Note:QGraphicsScene keeps the embedded widget in a special state that prevents it from disturbing other widgets (both embedded and not embedded) while the widget is embedded. In this state, the widget may differ slightly in behavior from when it is not embedded.

See also:
QGraphicsScene::addWidget(), and QGraphicsWidget.


Nested Class Summary
static class QGraphicsProxyWidget.enum_1
           
 
Nested classes/interfaces inherited from class com.trolltech.qt.QtJambiObject
QtJambiObject.QPrivateConstructor
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Constructor Summary
  QGraphicsProxyWidget()
          Constructs a new QGraphicsProxy widget.
  QGraphicsProxyWidget(QGraphicsItemInterface parent)
          Constructs a new QGraphicsProxy widget.
  QGraphicsProxyWidget(QGraphicsItemInterface parent, Qt.WindowFlags wFlags)
          Constructs a new QGraphicsProxy widget.
  QGraphicsProxyWidget(QGraphicsItemInterface parent, Qt.WindowType... wFlags)
          Constructs a new QGraphicsProxy widget.
protected QGraphicsProxyWidget(QtJambiObject.QPrivateConstructor p)
          This method is internal to Qt Jambi.
 
Method Summary
 void contextMenuEvent(QGraphicsSceneContextMenuEvent event)
          This method is reimplemented for internal reasons.
 boolean event(QEvent event)
          This method is reimplemented for internal reasons.
 boolean eventFilter(QObject object, QEvent event)
          This method is reimplemented for internal reasons.
 void focusInEvent(QFocusEvent event)
          This method is reimplemented for internal reasons.
protected  boolean focusNextPrevChild(boolean next)
          This method is reimplemented for internal reasons.
 void focusOutEvent(QFocusEvent event)
          This method is reimplemented for internal reasons.
static QGraphicsProxyWidget fromNativePointer(QNativePointer nativePointer)
          This method returns the QGraphicsProxyWidget instance pointed to by nativePointer.
protected  void grabMouseEvent(QEvent event)
          This method is reimplemented for internal reasons.
protected  void hideEvent(QHideEvent event)
          This method is reimplemented for internal reasons.
 void hoverEnterEvent(QGraphicsSceneHoverEvent event)
          This method is reimplemented for internal reasons.
 void hoverLeaveEvent(QGraphicsSceneHoverEvent event)
          This method is reimplemented for internal reasons.
 void hoverMoveEvent(QGraphicsSceneHoverEvent event)
          This method is reimplemented for internal reasons.
 java.lang.Object itemChange(QGraphicsItem.GraphicsItemChange change, java.lang.Object value)
          This method is reimplemented for internal reasons.
 void keyPressEvent(QKeyEvent event)
          This method is reimplemented for internal reasons.
 void keyReleaseEvent(QKeyEvent event)
          This method is reimplemented for internal reasons.
 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent event)
          This method is reimplemented for internal reasons.
 void mouseMoveEvent(QGraphicsSceneMouseEvent event)
          This method is reimplemented for internal reasons.
 void mousePressEvent(QGraphicsSceneMouseEvent event)
          This method is reimplemented for internal reasons.
 void mouseReleaseEvent(QGraphicsSceneMouseEvent event)
          This method is reimplemented for internal reasons.
 void paint(QPainter painter, QStyleOptionGraphicsItem option, QWidget widget)
          This method is reimplemented for internal reasons.
protected  void resizeEvent(QGraphicsSceneResizeEvent event)
          This method is reimplemented for internal reasons.
 void setGeometry(QRectF rect)
          This method is reimplemented for internal reasons.
 void setWidget(QWidget widget)
          Embeds widget into this proxy widget.
protected  void showEvent(QShowEvent event)
          This method is reimplemented for internal reasons.
 QSizeF sizeHint(Qt.SizeHint which, QSizeF constraint)
          This method is reimplemented for internal reasons.
 QRectF subWidgetRect(QWidget widget)
          Returns the rectangle for widget, which must be a descendant of widget(), or widget() itself, in this proxy item's local coordinates.
 int type()
          This method is reimplemented for internal reasons.
protected  void ungrabMouseEvent(QEvent event)
          This method is reimplemented for internal reasons.
 void wheelEvent(QGraphicsSceneWheelEvent event)
          This method is reimplemented for internal reasons.
 QWidget widget()
          Returns a pointer to the embedded widget.
 
Methods inherited from class com.trolltech.qt.gui.QGraphicsWidget
__qt_cast_to_QGraphicsItem, __qt_cast_to_QGraphicsLayoutItem, acceptDrops, acceptedMouseButtons, acceptHoverEvents, acceptsHoverEvents, addToIndex, adjustSize, advance, boundingRect, boundingRegion, boundingRegionGranularity, cacheMode, changeEvent, childItems, childrenBoundingRect, clearFocus, close, closeEvent, collidesWithItem, collidesWithPath, collidingItems, commonAncestorItem, contains, contentsRect, cursor, data, deviceTransform, dragEnterEvent, dragLeaveEvent, dragMoveEvent, dropEvent, effectiveSizeHint, ensureVisible, ensureVisible, extension, flags, focusPolicy, focusWidget, font, geometry, getContentsMargins, getWindowFrameMargins, grabKeyboard, grabKeyboardEvent, grabMouse, group, handlesChildEvents, hasCursor, hasFocus, hide, initStyleOption, inputMethodEvent, inputMethodQuery, installSceneEventFilter, isActiveWindow, isAncestorOf, isEnabled, isLayout, isObscured, isObscured, isObscured, isObscuredBy, isSelected, isUnderMouse, isVisible, isVisibleTo, isWidget, isWindow, layout, layoutDirection, mapFromItem, mapFromItem, mapFromItem, mapFromItem, mapFromItem, mapFromItem, mapFromParent, mapFromParent, mapFromParent, mapFromParent, mapFromParent, mapFromParent, mapFromScene, mapFromScene, mapFromScene, mapFromScene, mapFromScene, mapFromScene, mapToItem, mapToItem, mapToItem, mapToItem, mapToItem, mapToItem, mapToParent, mapToParent, mapToParent, mapToParent, mapToParent, mapToParent, mapToScene, mapToScene, mapToScene, mapToScene, mapToScene, mapToScene, maximumHeight, maximumSize, maximumWidth, minimumHeight, minimumSize, minimumWidth, moveBy, moveEvent, opaqueArea, paintWindowFrame, paintWindowFrame, palette, parentItem, parentLayoutItem, parentWidget, polishEvent, pos, preferredHeight, preferredSize, preferredWidth, prepareGeometryChange, propertyChange, rect, removeFromIndex, removeSceneEventFilter, resetTransform, resize, resize, rotate, scale, scene, sceneBoundingRect, sceneEvent, sceneEventFilter, scenePos, sceneTransform, scroll, setAcceptDrops, setAcceptedMouseButtons, setAcceptHoverEvents, setAcceptsHoverEvents, setAttribute, setAttribute, setBoundingRegionGranularity, setCacheMode, setContentsMargins, setCursor, setData, setEnabled, setExtension, setFlag, setFlags, setFocus, setFocusPolicy, setFont, setGeometry, setGroup, setHandlesChildEvents, setLayout, setLayoutDirection, setMaximumHeight, setMaximumSize, setMaximumSize, setMaximumWidth, setMinimumHeight, setMinimumSize, setMinimumSize, setMinimumWidth, setPalette, setParentItem, setParentLayoutItem, setPos, setPos, setPreferredHeight, setPreferredSize, setPreferredSize, setPreferredWidth, setSelected, setSizePolicy, setSizePolicy, setStyle, setTabOrder, setToolTip, setTransform, setVisible, setWindowFlags, setWindowFlags, setWindowFrameMargins, setWindowTitle, setZValue, shape, shear, show, size, sizePolicy, style, supportsExtension, testAttribute, toolTip, topLevelItem, topLevelWidget, transform, translate, ungrabKeyboard, ungrabKeyboardEvent, ungrabMouse, unsetCursor, unsetLayoutDirection, unsetWindowFrameMargins, update, update, updateGeometry, window, windowFlags, windowFrameEvent, windowFrameGeometry, windowFrameRect, windowFrameSectionAt, windowTitle, windowType, x, y, zValue
 
Methods inherited from class com.trolltech.qt.core.QObject
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent, toString, userProperty
 
Methods inherited from class com.trolltech.qt.QtJambiObject
disableGarbageCollection, dispose, disposed, equals, finalize, nativeId, nativePointer, reassignNativeResources, reenableGarbageCollection, setJavaOwnership, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
__qt_signalInitialization, disconnect, disconnect, signalSender
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QGraphicsProxyWidget

public QGraphicsProxyWidget(QGraphicsItemInterface parent,
                            Qt.WindowType... wFlags)
Constructs a new QGraphicsProxy widget. parent and wFlags are passed to QGraphicsItem's constructor.


QGraphicsProxyWidget

public QGraphicsProxyWidget(QGraphicsItemInterface parent)
Constructs a new QGraphicsProxy widget. parent and wFlags are passed to QGraphicsItem's constructor.


QGraphicsProxyWidget

public QGraphicsProxyWidget()
Constructs a new QGraphicsProxy widget. parent and wFlags are passed to QGraphicsItem's constructor.


QGraphicsProxyWidget

public QGraphicsProxyWidget(QGraphicsItemInterface parent,
                            Qt.WindowFlags wFlags)
Constructs a new QGraphicsProxy widget. parent and wFlags are passed to QGraphicsItem's constructor.


QGraphicsProxyWidget

protected QGraphicsProxyWidget(QtJambiObject.QPrivateConstructor p)
This method is internal to Qt Jambi.

Method Detail

setWidget

public final void setWidget(QWidget widget)
Embeds widget into this proxy widget. The embedded widget must reside exclusively either inside or outside of Graphics View. You cannot embed a widget as long as it is is visible elsewhere in the UI, at the same time.

widget must be a top-level widget whose parent is 0.

When the widget is embedded, its state (e.g., visible, enabled, geometry, size hints) is copied into the proxy widget. If the embedded widget is explicitly hidden or disabled, the proxy widget will become explicitly hidden or disabled after embedding is complete. The class documentation has a full overview over the shared state.

After this function returns, QGraphicsProxyWidget will keep its state synchronized with that of widget whenever possible.

If a widget is already embedded by this proxy when this function is called, that widget will first be automatically unembedded. Passing 0 for the widget argument will only unembed the widget, and the ownership of the currently embedded widget will be passed on to the caller.

See also:
widget().


subWidgetRect

public final QRectF subWidgetRect(QWidget widget)
Returns the rectangle for widget, which must be a descendant of widget(), or widget() itself, in this proxy item's local coordinates.

If no widget is embedded, widget is 0, or widget is not a descendant of the embedded widget, this function returns an empty QRectF.

See also:
widget().


widget

public final QWidget widget()
Returns a pointer to the embedded widget.

See also:
setWidget().


contextMenuEvent

public void contextMenuEvent(QGraphicsSceneContextMenuEvent event)
This method is reimplemented for internal reasons.

Specified by:
contextMenuEvent in interface QGraphicsItemInterface
Overrides:
contextMenuEvent in class QGraphicsWidget

event

public boolean event(QEvent event)
This method is reimplemented for internal reasons.

Overrides:
event in class QGraphicsWidget

eventFilter

public boolean eventFilter(QObject object,
                           QEvent event)
This method is reimplemented for internal reasons.

Overrides:
eventFilter in class QObject

focusInEvent

public void focusInEvent(QFocusEvent event)
This method is reimplemented for internal reasons.

Specified by:
focusInEvent in interface QGraphicsItemInterface
Overrides:
focusInEvent in class QGraphicsWidget

focusNextPrevChild

protected boolean focusNextPrevChild(boolean next)
This method is reimplemented for internal reasons.

Overrides:
focusNextPrevChild in class QGraphicsWidget

focusOutEvent

public void focusOutEvent(QFocusEvent event)
This method is reimplemented for internal reasons.

Specified by:
focusOutEvent in interface QGraphicsItemInterface
Overrides:
focusOutEvent in class QGraphicsWidget

grabMouseEvent

protected void grabMouseEvent(QEvent event)
This method is reimplemented for internal reasons.

Overrides:
grabMouseEvent in class QGraphicsWidget

hideEvent

protected void hideEvent(QHideEvent event)
This method is reimplemented for internal reasons.

Overrides:
hideEvent in class QGraphicsWidget

hoverEnterEvent

public void hoverEnterEvent(QGraphicsSceneHoverEvent event)
This method is reimplemented for internal reasons.

Specified by:
hoverEnterEvent in interface QGraphicsItemInterface
Overrides:
hoverEnterEvent in class QGraphicsWidget

hoverLeaveEvent

public void hoverLeaveEvent(QGraphicsSceneHoverEvent event)
This method is reimplemented for internal reasons.

Specified by:
hoverLeaveEvent in interface QGraphicsItemInterface
Overrides:
hoverLeaveEvent in class QGraphicsWidget

hoverMoveEvent

public void hoverMoveEvent(QGraphicsSceneHoverEvent event)
This method is reimplemented for internal reasons.

Specified by:
hoverMoveEvent in interface QGraphicsItemInterface
Overrides:
hoverMoveEvent in class QGraphicsWidget

itemChange

public java.lang.Object itemChange(QGraphicsItem.GraphicsItemChange change,
                                   java.lang.Object value)
This method is reimplemented for internal reasons.

Specified by:
itemChange in interface QGraphicsItemInterface
Overrides:
itemChange in class QGraphicsWidget

keyPressEvent

public void keyPressEvent(QKeyEvent event)
This method is reimplemented for internal reasons.

Specified by:
keyPressEvent in interface QGraphicsItemInterface
Overrides:
keyPressEvent in class QGraphicsWidget

keyReleaseEvent

public void keyReleaseEvent(QKeyEvent event)
This method is reimplemented for internal reasons.

Specified by:
keyReleaseEvent in interface QGraphicsItemInterface
Overrides:
keyReleaseEvent in class QGraphicsWidget

mouseDoubleClickEvent

public void mouseDoubleClickEvent(QGraphicsSceneMouseEvent event)
This method is reimplemented for internal reasons.

Specified by:
mouseDoubleClickEvent in interface QGraphicsItemInterface
Overrides:
mouseDoubleClickEvent in class QGraphicsWidget

mouseMoveEvent

public void mouseMoveEvent(QGraphicsSceneMouseEvent event)
This method is reimplemented for internal reasons.

Specified by:
mouseMoveEvent in interface QGraphicsItemInterface
Overrides:
mouseMoveEvent in class QGraphicsWidget

mousePressEvent

public void mousePressEvent(QGraphicsSceneMouseEvent event)
This method is reimplemented for internal reasons.

Specified by:
mousePressEvent in interface QGraphicsItemInterface
Overrides:
mousePressEvent in class QGraphicsWidget

mouseReleaseEvent

public void mouseReleaseEvent(QGraphicsSceneMouseEvent event)
This method is reimplemented for internal reasons.

Specified by:
mouseReleaseEvent in interface QGraphicsItemInterface
Overrides:
mouseReleaseEvent in class QGraphicsWidget

paint

public void paint(QPainter painter,
                  QStyleOptionGraphicsItem option,
                  QWidget widget)
This method is reimplemented for internal reasons.

Specified by:
paint in interface QGraphicsItemInterface
Overrides:
paint in class QGraphicsWidget

resizeEvent

protected void resizeEvent(QGraphicsSceneResizeEvent event)
This method is reimplemented for internal reasons.

Overrides:
resizeEvent in class QGraphicsWidget

setGeometry

public void setGeometry(QRectF rect)
This method is reimplemented for internal reasons.

Specified by:
setGeometry in interface QGraphicsLayoutItemInterface
Overrides:
setGeometry in class QGraphicsWidget

showEvent

protected void showEvent(QShowEvent event)
This method is reimplemented for internal reasons.

Overrides:
showEvent in class QGraphicsWidget

sizeHint

public QSizeF sizeHint(Qt.SizeHint which,
                       QSizeF constraint)
This method is reimplemented for internal reasons.

Specified by:
sizeHint in interface QGraphicsLayoutItemInterface
Overrides:
sizeHint in class QGraphicsWidget

type

public int type()
This method is reimplemented for internal reasons.

Specified by:
type in interface QGraphicsItemInterface
Overrides:
type in class QGraphicsWidget

ungrabMouseEvent

protected void ungrabMouseEvent(QEvent event)
This method is reimplemented for internal reasons.

Overrides:
ungrabMouseEvent in class QGraphicsWidget

wheelEvent

public void wheelEvent(QGraphicsSceneWheelEvent event)
This method is reimplemented for internal reasons.

Specified by:
wheelEvent in interface QGraphicsItemInterface
Overrides:
wheelEvent in class QGraphicsWidget

fromNativePointer

public static QGraphicsProxyWidget fromNativePointer(QNativePointer nativePointer)
This method returns the QGraphicsProxyWidget instance pointed to by nativePointer.