Home · All Classes · Main Classes · Grouped Classes · Modules · Functions

QGraphicsProxyWidget Class Reference
[
QtGui module]

The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene. More...

 #include <QGraphicsProxyWidget>

Inherits QGraphicsWidget.

This class was introduced in Qt 4.4.

Public Functions

Additional Inherited Members


Detailed Description

The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene.

QGraphicsProxyWidget embeds any QWidget-based widget into QGraphicsScene. It forwards events between the two 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, and you can also embed widgets with subwidgets.

Popup children of embedded widgets are automatically embedded as children of this proxy widget (e.g., QComboBox's popup is embedded together with the combo box).

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 the proxy or the widget directly. Alternatively, you can create a new QGraphicsProxyWidget item first, and then call setWidget() to embed a QWidget later. The widget() function returns a pointer to the embedded widget.

Any widget, including complex widgets with children, and dialogs, can be embedded.

Example:

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

     QTabWidget *tabWidget = new QTabWidget;

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

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

     return app.exec();
 }

QGraphicsProxyWidget keeps its state in sync with the embedded widget (i.e., if the proxy is hidden, so is the embedded widget). As a widget is embedded by calling addWidget(), QGraphicsProxyWidget copies the state from the widget into the proxy, and after that, the two stay synchronized where possible. If the proxy moves or resizes, the embedded widget will also move or resize (i.e., the proxy and embedded widget's geometries are in sync), and vice versa. If you show the embedded widget, the proxy will also become visible. As a side effect, QGraphicsProxyWidget becomes hidden if you embed a hidden line edit.

Example:

     QGraphicsScene scene;

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

     edit->isVisible();  // returns false, as QWidget is hidden by default
     proxy->isVisible(); // also returns false

     edit->show();

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

QGraphicsProxyWidget maintains symmetry for the following states:

QWidget stateQGraphicsProxyWidget stateNotes
QWidget::enabledQGraphicsProxyWidget::enabled
QWidget::visibleQGraphicsProxyWidget::visible
QWidget::geometryQGraphicsProxyWidget::geometryGeometry is only guaranteed to be symmetric while the embedded widget is visible.
QWidget::layoutDirectionQGraphicsProxyWidget::layoutDirection
QWidget::styleQGraphicsProxyWidget::style
QWidget::paletteQGraphicsProxyWidget::palette
QWidget::fontQGraphicsProxyWidget::font
QWidget::cursorQGraphicsProxyWidget::cursorThe proxy cursor changes based 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::windowTitleQGraphicsProxyWidget::windowTitleUpdated 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 embedded. In this state, it may differ slightly in behavior from when it is not embedded.

See also QGraphicsScene::addWidget() and QGraphicsWidget.


Member Function Documentation

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

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

QGraphicsProxyWidget::~QGraphicsProxyWidget ()

Destroys the proxy widget, and any embedded widget.

void QGraphicsProxyWidget::setWidget ( QWidget * widget )

Embeds widget into this proxy widget. widget must be a top-level widget whose parent is 0.

You can also pass 0 for the widget argument. This will remove the widget from this proxy, and pass ownership of the currently embedded widget to the caller.

See also widget().

QRectF QGraphicsProxyWidget::subWidgetRect ( const QWidget * widget ) const

Returns the rectangle for widget, which must be a descendent of widget(), or widget() itself, in this proxy item's local coordinates.

If widget is 0, this function returns an empty QRectF.

See also widget().

QWidget * QGraphicsProxyWidget::widget () const

Returns a pointer to the embedded widget.

See also setWidget().


Copyright © 2007 Trolltech Trademarks
Qt 4.4.0-tp1