가 QGraphicsScene
어떤 QWidget
기반 객체를 추가하려면 QGraphicsProxyWidget
이 필요합니다.
이 기능 QGraphicsScene
에 addWidget
전화
, 그것은
QGraphicsProxyWidget
에 위젯을 내장하고 반환 호출자에게 다시
QGraphicsProxyWidget
.
QGraphicsProxyWidget
은 위젯에 이벤트를 전달하고 다른 좌표계 간의 변환을 처리합니다.
QGraphicsScene* pScene = new QGraphicsScene;
QLineEdit* pLineEdit = new QLineEdit("Some Text");
// add the widget - internally, the QGraphicsProxyWidget is created and returned
QGraphicsProxyWidget* pProxyWidget = pScene->AddWidget(pLineEdit);
을하거나 현재 QGraphicsItem
에 추가 : 당신이 직접 추가 할 경우
은 이제 QGraphicsScene
에 QLineEdit
를 사용하여보고 있다는 것을, 당신은 결정해야합니다. 여기 , 당신은 QGraphicsItem
의 자식으로 추가 할 수 있습니다 :
MyQGraphicsItem* pMyItem = new MyQGraphicsItem;
QGraphicsProxyWidget* pMyProxy = new QGraphicsProxyWidget(pMyItem); // the proxy's parent is pMyItem
pMyProxy->setWidget(pLineEdit); // adding the QWidget based object to the proxy
또는 당신이 당신의 클래스의 구성원으로 QGraphicsProxyWidget
을 추가하고 관련 함수를 호출 할 수 있지만 아이로 추가하면 아마 훨씬 간단 .
@Freedom_Ben QLineEdit은 QWidget이므로 QGraphicsTextItem 대신 QLineEdit를 원한다면. 그런 다음 "mhcuervo"가 이미 답변 한 다른 방법을 사용하십시오. – Ashif
이 기능은 대부분이 기능을 간과하기 때문에 실제로 좋은 대답이었으며 QWidgets 및 관련 프록시 항목을 추가하는 것은 전반적인 성능은 말할 것도없이 단순함을 찾고 있다면 원치 않는 전체 웜 수 있습니다. – osirisgothra