[Qt-interest] mouse/dragdrop events in Qgraphics

Jaco Naude naude.jaco at gmail.com
Fri Nov 5 10:22:11 CET 2010


I compiled your exact code and I'm able to drag & drop without any
problems.
Using Qt 4.7 RC1.

Cheers,
Jaco

On Fri, Nov 5, 2010 at 8:13 AM, Mahendra G.R <mahendra at mahendragr.com>wrote:

> Hi all,
>
> i'm trying to implent dragdrop functionality in Qgraphics, but for some
> reason when i drag, the items(polygons in my case) are not moving.  i'm
> attaching the source code, can anyone please shed some light.
>
>
> int main(int argc, char *argv[])
>
>       {
>
>           QApplication a(argc, argv);
>
>           QGraphicsScene scene;
>     QGraphicsView view;
>     QPixmap pixmap("cross_out.PNG");
>     QPolygonF polygon1,polygon2;
>     QGraphicsPolygonItem item1,item2;
>
>     scene.addPixmap(pixmap);
>     scene.blockSignals(true);
>
>
>         polygon1 << QPointF(50.4, 20.5) << QPointF(100.2,
> 40.2)<<QPointF(100.2, 100.2)<<QPointF(50.4,100.5);
>     polygon2 << QPointF(200.4, 200.5) << QPointF(200.2,
> 90.2)<<QPointF(220.2, 100.2);
>     item1.setPen(QPen(Qt::red));
>     item1.setPolygon(polygon1);
>     item1.setAcceptDrops(true);
>     item1.setFlag(QGraphicsPolygonItem::ItemIsMovable);
>
>     item2.setPen(QPen(Qt::blue));
>     item2.setPolygon(polygon2);
>     item2.setAcceptDrops(true);
>     item2.setFlag(QGraphicsPolygonItem::ItemIsMovable);
>
>
>
>     scene.addItem(&item1);
>     scene.addItem(&item2);
>
>     view.setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
>     view.setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
>     view.setScene(&scene);
>     view.resize(300,300);
>     view.show();
>
>
>     return a.exec();
>
>       }
>
>
>
>
> which method(s) should i override, mouserelese/move/press events or the
> drag/drop events in order to move the polygons and get the current vertices
> of the polygon after it is moved.
>
>
>
> Thanks,
> Best regards
>
> --
> http://www.mahendragr.com
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101105/f9f750c3/attachment.html 


More information about the Qt-interest-old mailing list