您的位置:首页 > 其它

怎么把QLabel添加进QGraphicsItem

2014-01-23 15:05 197 查看
从国外网站找的答案;元标题是:How to add QLabel to QGraphicsItem

The QGraphicsProxyWidget forwards events to its widget and handles conversion between the different coordinate systems.

Now that you're looking at using a QLineEdit in the QGraphicsScene, you need to decide if you want to add it directly: -

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);

//Or just add it to your current QGraphicsItem. Here, you can either add it as a child of the 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


Or you could add the QGraphicsProxyWidget as a member of your class and call its relevant functions, but adding it as a child is probably much simpler.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: