[Qt-interest] Regarding polygons and mouse events
Mahendra G.R
mahendra at mahendragr.com
Wed Nov 10 10:33:51 CET 2010
Hello all,
I have a (another) problem now, i managed to move polygon inside a scene
using Qgraphicsscene. Now i have multiple polygons in the scene, i want to
move the polygons inside the scene. For example if i have blue/green
polygons, i want move them indiviually, my implementation does this for ONE
polygon, even if i i have two polygons in the scene, whenever i click the
second polygon, only the first polygon moves and the other stays idle all
the time. I have attached my code, any help will be really useful, i've
almost gave up on this bug..
----------------------
void CustomScene::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
{
QTextStream out(stdout);
out <<"Mouse released "<<endl;
double mousePosX;
double mousePosY;
mousePosX = (double) event->scenePos().x();
mousePosY = (double) event->scenePos().y();
out <<mousePosX<<" "<<mousePosY<<endl;
QPolygonF tempPoly;
QGraphicsPolygonItem *tempItem;
tempItem =
(QGraphicsPolygonItem*)this->itemAt(event->scenePos().x(),event->scenePos().y());
if (tempItem == 0)
{
out<<"Item not found "<<endl;
return;
}
tempPoly = tempItem->polygon();
//tempPoly1 = tempItem1->polygon();
QPointF p1,p2,p3,p4;
p1 = tempPoly.at(0);
p1 = tempItem->mapToParent(p1);
p2 = tempPoly.at(1);
p2 = tempItem->mapToParent(p2);
p3 = tempPoly.at(2);
p3 = tempItem->mapToParent(p3);
p4 = tempPoly.at(3);
p4 = tempItem->mapToParent(p4);
out <<"p1: "<<p1.x()<<" "<<p1.y()<<endl
<<"p2 : "<<" "<<p2.x()<<" "<<p2.y()<<endl
<<"p3 : "<<" "<<p3.x()<<" "<<p3.y()<<endl
<<"p4 : "<<" "<<p4.x()<<" "<<p4.y()<<endl;
}
----------------
I tried with mousePressEvent, but then i cant move the polygons at all!!,
this is the best possible way i could do it (or am i missing something??)
--
http://www.mahendragr.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101110/f3e0a2ab/attachment.html
More information about the Qt-interest-old
mailing list