问题描述
大家好.
我有一个关于QGraphicsItem的问题.
我已经将qml文件投射到QGraphicsItem(通过引擎创建对象).而且还可以.但是当我将此QGraphicsItem添加到场景和视图中并且将其标志设置为可移动时,当我尝试将其拖动时将无济于事.
这是代码:
< pre lang ="c ++">
QDeclarativeEngine引擎;
QDeclarativeComponent组件(& engine,QUrl :: fromLocalFile("qml/TabbedPage/Dial.qml")));
QObject * object = component.create();
QGraphicsItem * newItem = qobject_cast< QGraphicsItem *>(对象);
newItem-> setFlags(QGraphicsItem :: ItemIsSelectable | QGraphicsItem :: ItemIsMovable);
newItem-> setAcceptsHoverEvents(true);
newItem-> setAcceptedMouseButtons(Qt :: LeftButton);
scene.addItem(newItem);
view.setScene(& scene);
view.show();
</pre>
有什么问题? !
Hello everybody..
I''ve a question about QGraphicsItem.
I''ve casted a qml file to QGraphicsItem (by creating a object by engine). And it''s OK . But when i add this QGraphicsItem into a scene and view and i set its flag to be movable nothing will do when i try to drag it.
Here is the code:
<pre lang="c++">
QDeclarativeEngine engine;
QDeclarativeComponent component(&engine,QUrl::fromLocalFile("qml/TabbedPage/Dial.qml"));
QObject *object = component.create();
QGraphicsItem *newItem = qobject_cast<QGraphicsItem *>(object);
newItem->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
newItem->setAcceptsHoverEvents(true);
newItem->setAcceptedMouseButtons(Qt::LeftButton);
scene.addItem(newItem);
view.setScene(&scene);
view.show();
</pre>
What''s the problem? !
推荐答案
这篇关于从QML文件强制转换了QGraphicsItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!