4/6/2022

Virtual Slot In Qt

  1. Virtual Slot In Qts
  2. Virtual Slot In Qtc
  3. Virtual Slot In Qt Game
  4. Virtual Slot In Qt Download

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

Header:#include <QGraphicsProxyWidget>
qmake: QT += widgets
Since: Qt 4.4
Inherits:QGraphicsWidget
  1. The Qt signals/slots and property system are based on the ability to introspect the objects at runtime. Introspection means being able to list the methods and properties of an object and have all kinds of information about them such as the type of their arguments. QtScript and QML would have hardly been possible without that ability.
  2. The home slot sets the text to the very first document displayed. The anchorClicked signal is emitted when the user clicks an anchor. To override the default navigation behavior of the browser, call the setSource function to supply new document text in a slot connected to this signal.
  3. The signals and slots mechanism is a central feature of Qt and probably the part that differs most from the features provided by other frameworks. Signals and slots are made possible by Qt's meta-object system.
  4. There's no need to make it virtual (it already is per C semantics), and there's no need to make it a slot again (it already is per Qt semantics). It is incorrect to add the second connection in Derived, it'll simply result in the slot being activated twice per every activation of the signal.

Public Functions

QGraphicsProxyWidget(QGraphicsItem *parent = Q_NULLPTR, Qt::WindowFlags wFlags = Qt::WindowFlags())
~QGraphicsProxyWidget()
QGraphicsProxyWidget *createProxyForChildWidget(QWidget *child)
void setWidget(QWidget *widget)
QRectF subWidgetRect(const QWidget *widget) const
QWidget *widget() const

This function is a fake virtual slot that you can reimplement in your subclass in order to control how new proxy widgets are created. The default implementation returns a proxy created with the QGraphicsProxyWidget constructor with this proxy widget as the parent.

Reimplemented Public Functions

virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
virtual void setGeometry(const QRectF &rect)
virtual int type() const
  • 53 public functions inherited from QGraphicsWidget
  • 2 public functions inherited from QGraphicsObject
  • 35 public functions inherited from QGraphicsLayoutItem
  • 31 public functions inherited from QObject
  • 176 public functions inherited from QGraphicsItem

Reimplemented Protected Functions

Virtual
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event)
virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *event)
virtual void dropEvent(QGraphicsSceneDragDropEvent *event)
virtual bool event(QEvent *event)
virtual bool eventFilter(QObject *object, QEvent *event)
virtual void focusInEvent(QFocusEvent *event)
virtual bool focusNextPrevChild(bool next)
virtual void focusOutEvent(QFocusEvent *event)
virtual void grabMouseEvent(QEvent *event)
virtual void hideEvent(QHideEvent *event)
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
virtual void inputMethodEvent(QInputMethodEvent *event)
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
virtual void keyPressEvent(QKeyEvent *event)
virtual void keyReleaseEvent(QKeyEvent *event)
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
virtual void resizeEvent(QGraphicsSceneResizeEvent *event)
virtual void showEvent(QShowEvent *event)
virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const
virtual void ungrabMouseEvent(QEvent *event)
virtual void wheelEvent(QGraphicsSceneWheelEvent *event)
  • 24 protected functions inherited from QGraphicsWidget
  • 1 protected function inherited from QGraphicsObject
  • 3 protected functions inherited from QGraphicsLayoutItem
  • 9 protected functions inherited from QObject
  • 24 protected functions inherited from QGraphicsItem

Protected Slots

QGraphicsProxyWidget *newProxyWidget(const QWidget *child)
  • 1 protected slot inherited from QGraphicsObject

Additional Inherited Members

  • 14 properties inherited from QGraphicsWidget
  • 12 properties inherited from QGraphicsObject
  • 1 property inherited from QObject
  • 1 public slot inherited from QGraphicsWidget
  • 1 public slot inherited from QObject
  • 1 signal inherited from QGraphicsWidget
  • 9 signals inherited from QGraphicsObject
  • 2 signals inherited from QObject
  • 1 public variable inherited from QObject
  • 1 static public member inherited from QGraphicsWidget
  • 10 static public members inherited from QObject
  • 2 static public members inherited from QGraphicsItem
  • 24 protected functions inherited from QGraphicsWidget
  • 1 protected function inherited from QGraphicsObject
  • 3 protected functions inherited from QGraphicsLayoutItem
  • 9 protected functions inherited from QObject
  • 24 protected functions inherited from QGraphicsItem
  • 2 protected variables inherited from QObject

Detailed Description

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

QGraphicsProxyWidget embeds QWidget-based widgets, 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:

Virtual Slot In Qt

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. This only works if the popup is child of the embedded widget (for example QToolButton::setMenu() requires the QMenu instance to be child of the QToolButton).

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

QGraphicsProxyWidget maintains symmetry for the following states:

QWidget stateQGraphicsProxyWidget stateNotes
QWidget::enabledQGraphicsProxyWidget::enabled
QWidget::visibleQGraphicsProxyWidget::visibleThe explicit state is also symmetric.
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 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::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 the widget is embedded. In this state, the widget may differ slightly in behavior from when it is not embedded.

Warning: This class is provided for convenience when bridging QWidgets and QGraphicsItems, it should not be used for high-performance scenarios.

See also QGraphicsScene::addWidget() and QGraphicsWidget.

Member Function Documentation

QGraphicsProxyWidget::QGraphicsProxyWidget(QGraphicsItem *parent = Q_NULLPTR, Qt::WindowFlagswFlags = Qt::WindowFlags())

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

QGraphicsProxyWidget::~QGraphicsProxyWidget()

Destroys the proxy widget and any embedded widget.

[virtual protected] void QGraphicsProxyWidget::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)

Reimplemented from QGraphicsItem::contextMenuEvent().

QGraphicsProxyWidget *QGraphicsProxyWidget::createProxyForChildWidget(QWidget *child)

Creates a proxy widget for the given child of the widget contained in this proxy.

Virtual Slot In Qt

This function makes it possible to acquire proxies for non top-level widgets. For instance, you can embed a dialog, and then transform only one of its widgets.

If the widget is already embedded, return the existing proxy widget.

This function was introduced in Qt 4.5.

See also newProxyWidget() and QGraphicsScene::addWidget().

[virtual protected] void QGraphicsProxyWidget::dragEnterEvent(QGraphicsSceneDragDropEvent *event)

Reimplemented from QGraphicsItem::dragEnterEvent().

[virtual protected] void QGraphicsProxyWidget::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)

Reimplemented from QGraphicsItem::dragLeaveEvent().

[virtual protected] void QGraphicsProxyWidget::dragMoveEvent(QGraphicsSceneDragDropEvent *event)

Reimplemented from QGraphicsItem::dragMoveEvent().

[virtual protected] void QGraphicsProxyWidget::dropEvent(QGraphicsSceneDragDropEvent *event)

Reimplemented from QGraphicsItem::dropEvent().

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

Reimplemented from QObject::event().

[virtual protected] bool QGraphicsProxyWidget::eventFilter(QObject *object, QEvent *event)

Reimplemented from QObject::eventFilter().

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

Reimplemented from QGraphicsItem::focusInEvent().

[virtual protected] bool QGraphicsProxyWidget::focusNextPrevChild(boolnext)

Reimplemented from QGraphicsWidget::focusNextPrevChild().

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

Reimplemented from QGraphicsItem::focusOutEvent().

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

Reimplemented from QGraphicsWidget::grabMouseEvent().

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

Reimplemented from QGraphicsWidget::hideEvent().

[virtual protected] void QGraphicsProxyWidget::hoverEnterEvent(QGraphicsSceneHoverEvent *event)

Virtual Slot In Qts

Reimplemented from QGraphicsItem::hoverEnterEvent().

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

Reimplemented from QGraphicsItem::hoverLeaveEvent().

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

Reimplemented from QGraphicsItem::hoverMoveEvent().

[virtual protected] void QGraphicsProxyWidget::inputMethodEvent(QInputMethodEvent *event)

Reimplemented from QGraphicsItem::inputMethodEvent().

[virtual protected] QVariant QGraphicsProxyWidget::inputMethodQuery(Qt::InputMethodQueryquery) const

Reimplemented from QGraphicsItem::inputMethodQuery().

[virtual protected] QVariant QGraphicsProxyWidget::itemChange(GraphicsItemChangechange, const QVariant &value)

Reimplemented from QGraphicsItem::itemChange().

[virtual protected] void QGraphicsProxyWidget::keyPressEvent(QKeyEvent *event)

Reimplemented from QGraphicsItem::keyPressEvent().

[virtual protected] void QGraphicsProxyWidget::keyReleaseEvent(QKeyEvent *event)

Reimplemented from QGraphicsItem::keyReleaseEvent().

[virtual protected] void QGraphicsProxyWidget::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)

Reimplemented from QGraphicsItem::mouseDoubleClickEvent().

Virtual Slot In Qtc

[virtual protected] void QGraphicsProxyWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event)

Reimplemented from QGraphicsItem::mouseMoveEvent().

[virtual protected] void QGraphicsProxyWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)

Reimplemented from QGraphicsItem::mousePressEvent().

[virtual protected] void QGraphicsProxyWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)

Reimplemented from QGraphicsItem::mouseReleaseEvent().

[protected slot] QGraphicsProxyWidget *QGraphicsProxyWidget::newProxyWidget(const QWidget *child)

Creates a proxy widget for the given child of the widget contained in this proxy.

You should not call this function directly; use QGraphicsProxyWidget::createProxyForChildWidget() instead.

This function is a fake virtual slot that you can reimplement in your subclass in order to control how new proxy widgets are created. The default implementation returns a proxy created with the QGraphicsProxyWidget() constructor with this proxy widget as the parent.

This function was introduced in Qt 4.5.

See also createProxyForChildWidget().

[virtual] void QGraphicsProxyWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)

Reimplemented from QGraphicsItem::paint().

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

Reimplemented from QGraphicsWidget::resizeEvent().

[virtual] void QGraphicsProxyWidget::setGeometry(const QRectF &rect)

Reimplemented from QGraphicsLayoutItem::setGeometry().

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

Virtual Slot In Qt Game

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.

QGraphicsProxyWidget's window flags determine whether the widget, after embedding, will be given window decorations or not.

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. Every child widget that are embedded will also be embedded and their proxy widget destroyed.

Note that widgets with the Qt::WA_PaintOnScreen widget attribute set and widgets that wrap an external application or controller cannot be embedded. Examples are QGLWidget and QAxWidget.

See also widget().

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

Reimplemented from QGraphicsWidget::showEvent().

[virtual protected] QSizeF QGraphicsProxyWidget::sizeHint(Qt::SizeHintwhich, const QSizeF &constraint = QSizeF()) const

Reimplemented from QGraphicsLayoutItem::sizeHint().

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

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().

[virtual] int QGraphicsProxyWidget::type() const

Reimplemented from QGraphicsItem::type().

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

Reimplemented from QGraphicsWidget::ungrabMouseEvent().

[virtual protected] void QGraphicsProxyWidget::wheelEvent(QGraphicsSceneWheelEvent *event)

Reimplemented from QGraphicsItem::wheelEvent().

QWidget *QGraphicsProxyWidget::widget() const

Returns a pointer to the embedded widget.

Virtual Slot In Qt Download

See also setWidget().