The QGraphicsProxyWidget 類提供代理層為嵌入 QWidget 在 QGraphicsScene . 更多...
| 頭: | #include <QGraphicsProxyWidget> |
| qmake: | QT += widgets |
| Since: | Qt 4.4 |
| 繼承: | QGraphicsWidget |
| 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 |
| virtual void | paint (QPainter * painter , const QStyleOptionGraphicsItem * option , QWidget * widget ) |
| virtual void | setGeometry (const QRectF & rect ) |
| virtual int | type () const |
| 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 ) |
| QGraphicsProxyWidget * | newProxyWidget (const QWidget * child ) |
The QGraphicsProxyWidget 類提供代理層為嵌入 QWidget 在 QGraphicsScene .
QGraphicsProxyWidget 嵌入 QWidget 基小部件,例如 QPushButton , QFontComboBox ,或者甚至 QFileDialog ,進 QGraphicsScene 。它在 2 對象之間轉發事件和平移介於 QWidget 基於整數的幾何圖形和 QGraphicsWidget 基於 qreal 的幾何體。 QGraphicsProxyWidget 支持所有核心特徵對於 QWidget ,包括 Tab 焦點、鍵盤輸入、拖放及彈齣窗口。還可以嵌入復雜 Widget,如:帶子小部件的小部件。
範例:
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. 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 ).
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:
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 () 以嵌入 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.
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.
範例:
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:
注意: 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.
警告: This class is provided for convenience when bridging QWidgets and QGraphicsItems, it should not be used for high-performance scenarios.
另請參閱 QGraphicsScene::addWidget () 和 QGraphicsWidget .
構造新的 QGraphicsProxy 小部件。 parent and wFlags 被傳遞給 QGraphicsItem 的構造函數。
銷毀代理 Widget 和任何嵌入 Widget。
[virtual protected]
void
QGraphicsProxyWidget::
contextMenuEvent
(
QGraphicsSceneContextMenuEvent
*
event
)
重實現自 QGraphicsItem::contextMenuEvent ().
創建代理 Widget 為給定 child of the widget contained in this proxy.
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.
該函數在 Qt 4.5 引入。
另請參閱 newProxyWidget () 和 QGraphicsScene::addWidget ().
[virtual protected]
void
QGraphicsProxyWidget::
dragEnterEvent
(
QGraphicsSceneDragDropEvent
*
event
)
重實現自 QGraphicsItem::dragEnterEvent ().
[virtual protected]
void
QGraphicsProxyWidget::
dragLeaveEvent
(
QGraphicsSceneDragDropEvent
*
event
)
重實現自 QGraphicsItem::dragLeaveEvent ().
[virtual protected]
void
QGraphicsProxyWidget::
dragMoveEvent
(
QGraphicsSceneDragDropEvent
*
event
)
重實現自 QGraphicsItem::dragMoveEvent ().
[virtual protected]
void
QGraphicsProxyWidget::
dropEvent
(
QGraphicsSceneDragDropEvent
*
event
)
重實現自 QGraphicsItem::dropEvent ().
[virtual protected]
bool
QGraphicsProxyWidget::
event
(
QEvent
*
event
)
重實現自 QObject::event ().
[virtual protected]
bool
QGraphicsProxyWidget::
eventFilter
(
QObject
*
object
,
QEvent
*
event
)
重實現自 QObject::eventFilter ().
[virtual protected]
void
QGraphicsProxyWidget::
focusInEvent
(
QFocusEvent
*
event
)
重實現自 QGraphicsItem::focusInEvent ().
[virtual protected]
bool
QGraphicsProxyWidget::
focusNextPrevChild
(
bool
next
)
重實現自 QGraphicsWidget::focusNextPrevChild ().
[virtual protected]
void
QGraphicsProxyWidget::
focusOutEvent
(
QFocusEvent
*
event
)
重實現自 QGraphicsItem::focusOutEvent ().
[virtual protected]
void
QGraphicsProxyWidget::
grabMouseEvent
(
QEvent
*
event
)
重實現自 QGraphicsWidget::grabMouseEvent ().
[virtual protected]
void
QGraphicsProxyWidget::
hideEvent
(
QHideEvent
*
event
)
重實現自 QGraphicsWidget::hideEvent ().
[virtual protected]
void
QGraphicsProxyWidget::
hoverEnterEvent
(
QGraphicsSceneHoverEvent
*
event
)
重實現自 QGraphicsItem::hoverEnterEvent ().
[virtual protected]
void
QGraphicsProxyWidget::
hoverLeaveEvent
(
QGraphicsSceneHoverEvent
*
event
)
重實現自 QGraphicsItem::hoverLeaveEvent ().
[virtual protected]
void
QGraphicsProxyWidget::
hoverMoveEvent
(
QGraphicsSceneHoverEvent
*
event
)
重實現自 QGraphicsItem::hoverMoveEvent ().
[virtual protected]
void
QGraphicsProxyWidget::
inputMethodEvent
(
QInputMethodEvent
*
event
)
重實現自 QGraphicsItem::inputMethodEvent ().
[virtual protected]
QVariant
QGraphicsProxyWidget::
inputMethodQuery
(
Qt::InputMethodQuery
query
) const
重實現自 QGraphicsItem::inputMethodQuery ().
[virtual protected]
QVariant
QGraphicsProxyWidget::
itemChange
(
GraphicsItemChange
change
, const
QVariant
&
value
)
重實現自 QGraphicsItem::itemChange ().
[virtual protected]
void
QGraphicsProxyWidget::
keyPressEvent
(
QKeyEvent
*
event
)
重實現自 QGraphicsItem::keyPressEvent ().
[virtual protected]
void
QGraphicsProxyWidget::
keyReleaseEvent
(
QKeyEvent
*
event
)
重實現自 QGraphicsItem::keyReleaseEvent ().
[virtual protected]
void
QGraphicsProxyWidget::
mouseDoubleClickEvent
(
QGraphicsSceneMouseEvent
*
event
)
重實現自 QGraphicsItem::mouseDoubleClickEvent ().
[virtual protected]
void
QGraphicsProxyWidget::
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
)
重實現自 QGraphicsItem::mouseMoveEvent ().
[virtual protected]
void
QGraphicsProxyWidget::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
重實現自 QGraphicsItem::mousePressEvent ().
[virtual protected]
void
QGraphicsProxyWidget::
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
)
重實現自 QGraphicsItem::mouseReleaseEvent ().
[protected slot]
QGraphicsProxyWidget
*QGraphicsProxyWidget::
newProxyWidget
(const
QWidget
*
child
)
創建代理 Widget 為給定 child of the widget contained in this proxy.
您不應該直接調用此函數。使用 QGraphicsProxyWidget::createProxyForChildWidget () 代替。
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.
該函數在 Qt 4.5 引入。
另請參閱 createProxyForChildWidget ().
[虛擬]
void
QGraphicsProxyWidget::
paint
(
QPainter
*
painter
, const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
)
重實現自 QGraphicsItem::paint ().
[virtual protected]
void
QGraphicsProxyWidget::
resizeEvent
(
QGraphicsSceneResizeEvent
*
event
)
重實現自 QGraphicsWidget::resizeEvent ().
[虛擬]
void
QGraphicsProxyWidget::
setGeometry
(const
QRectF
&
rect
)
重實現自 QGraphicsLayoutItem::setGeometry ().
嵌入 widget 到此代理 Widget。嵌入 Widget 必須獨占位於圖形視圖內部 (或外部)。Widget 就無法嵌入,隻要在 UI 的其它地方同時可見。
widget must be a top-level widget whose parent is 0.
當 Widget 嵌入時,其狀態 (如:可見、啓用、幾何體、尺寸提示) 會被拷貝到代理小部件。若嵌入小部件被明確隱藏或禁用,代理 Widget 將在嵌入完成後變為被明確隱藏或禁用。類文檔編製對共享狀態有完整概述。
QGraphicsProxyWidget 的窗口標誌確定 Widget 在嵌入後,是否賦予其窗口裝飾。
此函數返迴後, QGraphicsProxyWidget 將同步保持其狀態同 widget 每當可能時。
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 自變量僅取消嵌入 Widget,且目前嵌入 Widget 的所有權會被傳遞給調用者。每個嵌入子級 Widget 也被嵌入,且它們的代理 Widget 會被銷毀。
注意:Widget 具有 Qt::WA_PaintOnScreen widget attribute set and widgets that wrap an external application or controller cannot be embedded. Examples are QGLWidget and QAxWidget .
另請參閱 widget ().
[virtual protected]
void
QGraphicsProxyWidget::
showEvent
(
QShowEvent
*
event
)
重實現自 QGraphicsWidget::showEvent ().
[virtual protected]
QSizeF
QGraphicsProxyWidget::
sizeHint
(
Qt::SizeHint
which
, const
QSizeF
&
constraint
= QSizeF()) const
重實現自 QGraphicsLayoutItem::sizeHint ().
Returns the rectangle for widget , which must be a descendant of widget (),或 widget () itself, in this proxy item's local coordinates.
若沒有嵌入小部件, widget is 0, or widget is not a descendant of the embedded widget, this function returns an empty QRectF .
另請參閱 widget ().
[虛擬]
int
QGraphicsProxyWidget::
type
() const
重實現自 QGraphicsItem::type ().
[virtual protected]
void
QGraphicsProxyWidget::
ungrabMouseEvent
(
QEvent
*
event
)
重實現自 QGraphicsWidget::ungrabMouseEvent ().
[virtual protected]
void
QGraphicsProxyWidget::
wheelEvent
(
QGraphicsSceneWheelEvent
*
event
)
重實現自 QGraphicsItem::wheelEvent ().
返迴嵌入 Widget 指針。
另請參閱 setWidget ().