从QML文件强制转换了QGraphicsItem [英] Casted QGraphicsItem from qml file

查看:159
本文介绍了从QML文件强制转换了QGraphicsItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.
我有一个关于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? !

推荐答案

我已经找到了!不可能!!但可以将其强制转换为QGraphicsObject
I''ve found it!That''s Not possible!! but it can be casted to QGraphicsObject


这篇关于从QML文件强制转换了QGraphicsItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆