[solved]Drag and drop between two QGraphicViews in single widget
-
You should not create a new scene and a new view each time you drop.
Just set a scene on your view after you created it and add your new item to that scene. -
Hi again,
But how to access the graphicsView which is the object of the @Widget::ui->graphicsView@ This cannot be accessed directly as its from a non- static member. It would be great if you could provide me the code how to use it in another class gview, for setting the scene in this view @ graphicsView and graphicsView2 @ Both are QGraphicView created using QTDesigner
Thanks and regards
Venkatesh Padmanabhan -
Create the scenes in Widget's constructor and set them your graphics views using setScene and then access them in your drop event using the scene() function
-
Hi,
Thanks for your valuable response. I have a problem, how to access the scenes declared in the constructor of WIDGET using scene() in drop event. I couldn't find a method to access those @ scn1 and scn @
declared in Widget using @ scene() @ -
You have to call it on the views you are implementing
-
I have created an object of class Widget in class gview to call upon @graphicsView1
graphicsView2
@ and created new scenes to accommodate it in gview, but it gets terminated when application starts to run.As you guided, how can I call upon the class using any other method?
I have tried @
Widget *wid = new Widget();
wid->ui->scn1->additem(item);
wid->ui->scn2->additem(item);
update();@
The item is the qgraphicspixmapitem, declared in gview as a pointer. I am not sure whether declaration is correct too@ QGraphicsPixmapItem *item; @
And used it for the variant_cast. I am not sure what's the mistake I am doing, as the application terminates as soon as I drop the image into the view.
-
Hi SGaint,
Atlast i was able to drag and drop the images into the qgraphicsview.I used
@ scene()->setPixmap(pixmap); @Thank you so much for your wonderful guidance.
Regards,
Venkatesh Padmanabhan. -
You're welcome
Don't forget to update the thread's title prepending solved so other forum users may know that a solution has been found :)
-
Hi,
I would like to ask one more query related to the original post. I am able to drag and drop images into the view now. But it doesn't work with Url's from local file, if i want to drag an image from the desktop into QGraphicsView it doesn't work as i think it is passed as Url not as an image i hope. It would be great help if you could suggest how to cast an Url into QPixmap... Awaiting your response. -
I'd rather answer on your other "post":http://qt-project.org/forums/viewthread/31764/