PDA

View Full Version : QGraphicsWidget and ItemIsMovable()



paolom
20th October 2009, 11:59
Hi...

I've a QGraphicsWidget and I want to select it..

I use the


setFlag(QGraphicsWidget::ItemIsMovable, true);

or the same:


setFlag(QGraphicsItem::ItemIsMovable,true);

but it doesn't work. I've reimplemented the paint method to draw the image.

If I use the QGraphicsPixmapItem (using the same code line) it works..

Where is my mistake?! Does the use of the paint method can "disable" the movable function of the items?

Thanks

scascio
20th October 2009, 12:19
If you want to make your item selectable, try QGraphicsItem::ItemIsSelectable ! :D

paolom
20th October 2009, 12:21
No...

I want to move it...

also isSelectable() doesn't works....

If I try to use the mouseEvent() on the item, the application ignore it...also no other classes (like scene or view) have QGraphicsSceneEvent or QMouseEvent...

why?!

scascio
20th October 2009, 12:27
Overloading paint method does not disable anything.

But are you sure you are drawing your item at the right place?
Do the boundingRect and paint are working in relative coordinates of your item?

Maybe your try to select the result of the draw that is outside of the rect of the item.

wagmare
20th October 2009, 12:27
try QGraphicsWidget as seperate object as widgetItem and do painting ..

and in QGraphicsView

scene->addItem(widgetItem);
widgetItem->setFlags(QGraphicsItem::ItemIsMovable);

paolom
20th October 2009, 12:39
wagmare I've try your solution and It doesn't work...

scascio I'm sure....I draw a number of images in this graphicscene and the bounding rect of each image has the image's geometry.

I can't understand why the application ignore the mouse event on my graphicsItem... I don't use any fuction to disable mouse button event....

Any ideas?

Thanks

Another thing...If I use the QGraphicsSceneMouseEvent on the scene to get the item with mapfromScene() it works!!!!

That's strange...the item exist for the scene...

paolom
20th October 2009, 14:18
I've solved....using a sublcasses of QGraphicsItem instead QGraphicsWidget

Thanks!

scascio
20th October 2009, 14:22
So, it the scene see the item at the right place,
and if what you are trying to do works with a PixmapItem,
we need to look further into your custom item.

Could you post it or a simplified version of it?

paolom
20th October 2009, 14:25
I create a subclass of QGraphicsItem...

after to use the IsMovableItem() function...I need to disable all the QGraphicsScene mousEvent method...

The problem is that before I subclassed QGraphicsWidget!!

That's all!!