Results 1 to 9 of 9

Thread: QGraphicsWidget and ItemIsMovable()

  1. #1
    Join Date
    Oct 2009
    Posts
    70

    Default QGraphicsWidget and ItemIsMovable()

    Hi...

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

    I use the

    Qt Code:
    1. setFlag(QGraphicsWidget::ItemIsMovable, true);
    To copy to clipboard, switch view to plain text mode 

    or the same:

    Qt Code:
    1. setFlag(QGraphicsItem::ItemIsMovable,true);
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsWidget and ItemIsMovable()

    If you want to make your item selectable, try QGraphicsItem::ItemIsSelectable !

  3. #3
    Join Date
    Oct 2009
    Posts
    70

    Default Re: QGraphicsWidget and ItemIsMovable()

    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?!

  4. #4
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsWidget and ItemIsMovable()

    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.

  5. #5
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsWidget and ItemIsMovable()

    try QGraphicsWidget as seperate object as widgetItem and do painting ..

    and in QGraphicsView
    Qt Code:
    1. scene->addItem(widgetItem);
    2. widgetItem->setFlags(QGraphicsItem::ItemIsMovable);
    To copy to clipboard, switch view to plain text mode 
    "Behind every great fortune lies a crime" - Balzac

  6. #6
    Join Date
    Oct 2009
    Posts
    70

    Default Re: QGraphicsWidget and ItemIsMovable()

    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...

  7. #7
    Join Date
    Oct 2009
    Posts
    70

    Default Re: QGraphicsWidget and ItemIsMovable()

    I've solved....using a sublcasses of QGraphicsItem instead QGraphicsWidget

    Thanks!

  8. #8
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsWidget and ItemIsMovable()

    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?

  9. #9
    Join Date
    Oct 2009
    Posts
    70

    Default Re: QGraphicsWidget and ItemIsMovable()

    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!!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.