PDA

View Full Version : Casted QGraphicsItem from qml file Won't works fine!



alizadeh91
25th February 2012, 11:07
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:

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

What's the problem? !

MarekR22
25th February 2012, 16:39
Try cast to QDeclarativeItem* like in exmple.

alizadeh91
25th February 2012, 17:42
Thanks MarekR22 for reply :)
I've tried that example, just like QGraphicsItem the Object is OK!! but it can't be moved by dragging in the scene.
It must be a way.. I'm so confused :(..

Added after 28 minutes:

For more info.: The qml Item will add to the scene, but the problem is that the drag and drop won't work. (When i set flag to QGraphicsItem::ItemisMovable, nothing happens and drag and drop still won't work.
Plz someone help me :(

alizadeh91
27th February 2012, 08:46
It's so weired!! No one have evered faced with this kinda problem!?

wysota
27th February 2012, 08:54
Please provide a minimal compilable example reproducing the problem.