PDA

View Full Version : ItemIsMovable???



konvex
12th December 2008, 12:55
Hi,
I want to move an item, but only if I press the right mousebutton.
Can somebody tell me how to do this?
I've tried this:


void GraphicsScene::mousePressEvent(QGraphicsSceneMouse Event *e)
{
pos=e->scenePos();
end=e->scenePos();
item = new EllipseItem(pos.x(), pos.y(),10,10);
item2 = new EllipseItem(end.x(), end.y(),10,10);

if(e->button() == Qt::LeftButton)
{
if(itemAt(pos))
{ QGraphicsScene::mousePressEvent(e); }

else
{
addItem(item);
addItem(item2);

linie = new LineItem(item,item2);
addItem(linie);
}
}

if(e->button() == Qt::RightButton)
{
item->setFlags(QGraphicsItem::ItemIsMovable);
item2->setFlags(QGraphicsItem::ItemIsMovable);
}
//this doesn't works
}

jpn
12th December 2008, 15:00
See QGraphicsItem::setAcceptedMouseButtons().

konvex
13th December 2008, 09:06
The right button works. But although the items are not movable?!

tupu_83
13th December 2008, 16:01
When you press the right mouse button, two items are created but these aren't added to scene. So the scene does not contain anything to mark with ItemIsMovable flag...