pkj
9th January 2013, 15:49
In Qt4.8 we can use to Qml to create QGraphicsObject as described in the documentation as :qml-integration.html#adding-qml-widgets-to-a-qgraphicsscene
QGraphicsScene* scene = myExistingGraphicsScene();
QDeclarativeEngine *engine = new QDeclarativeEngine;
QDeclarativeComponent component(engine, QUrl::fromLocalFile("myqml.qml"));
QGraphicsObject *object =
qobject_cast<QGraphicsObject *>(component.create());
scene->addItem(object);
I want the type() of QGraphicsItem in the QGraphicsObject i get from the factory function of QDeclarativeComponent to be set to something different from the default 'User' set in QGraphicsItem.
As described in the docs here qgraphicsitem.html#type I need to subclass the QgraphicsItem.
If I go ahead and do something like
class QmlObject : public QGraphicsObject{
Q_OBJECT
public:
enum {Type = TypeMyType;}//TypeMyType = UserType+1;
int type() const { return Type; }
QmlObject ();
}
QmlObject :: QmlObject () : QGraphicsObject()
{
QGraphicsScene* scene = myExistingGraphicsScene();
QDeclarativeEngine *engine = new QDeclarativeEngine;
QDeclarativeComponent component(engine, QUrl::fromLocalFile("myqml.qml"));
QGraphicsObject *object =
qobject_cast<QGraphicsObject *>(component.create());
scene->addItem(object);
//DEAD END HERE, can't change the embedded QGraphicsObject already initialized.
}
So if I go ahead by this route, since QObject is not copyable by Q_DISABLE_COPY, there is no way left for me to subclass it. And if I can't subclass it, I can't set the type of QGraphicsItem to something other than User.
AnyIdea how to go ahead and set the type of the QGraphicsItem?
QGraphicsScene* scene = myExistingGraphicsScene();
QDeclarativeEngine *engine = new QDeclarativeEngine;
QDeclarativeComponent component(engine, QUrl::fromLocalFile("myqml.qml"));
QGraphicsObject *object =
qobject_cast<QGraphicsObject *>(component.create());
scene->addItem(object);
I want the type() of QGraphicsItem in the QGraphicsObject i get from the factory function of QDeclarativeComponent to be set to something different from the default 'User' set in QGraphicsItem.
As described in the docs here qgraphicsitem.html#type I need to subclass the QgraphicsItem.
If I go ahead and do something like
class QmlObject : public QGraphicsObject{
Q_OBJECT
public:
enum {Type = TypeMyType;}//TypeMyType = UserType+1;
int type() const { return Type; }
QmlObject ();
}
QmlObject :: QmlObject () : QGraphicsObject()
{
QGraphicsScene* scene = myExistingGraphicsScene();
QDeclarativeEngine *engine = new QDeclarativeEngine;
QDeclarativeComponent component(engine, QUrl::fromLocalFile("myqml.qml"));
QGraphicsObject *object =
qobject_cast<QGraphicsObject *>(component.create());
scene->addItem(object);
//DEAD END HERE, can't change the embedded QGraphicsObject already initialized.
}
So if I go ahead by this route, since QObject is not copyable by Q_DISABLE_COPY, there is no way left for me to subclass it. And if I can't subclass it, I can't set the type of QGraphicsItem to something other than User.
AnyIdea how to go ahead and set the type of the QGraphicsItem?