Results 1 to 3 of 3

Thread: QGraphicsScene - clone selected item by Alt+Move

  1. #1
    Join Date
    Dec 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question QGraphicsScene - clone selected item by Alt+Move

    Hi!
    I want clone selected item at QGraphicsScene if user start moving item with pressed Alt.
    I wrote this code:
    Qt Code:
    1. if(mouseEvent->modifiers() == Qt::AltModifier)
    2. {
    3. QList<QGraphicsItem *> itList = this->selectedItems();
    4. if(itList.size()==1)
    5. {
    6. DiagramElement *de = (DiagramElement*)itList[0];
    7. DiagramElement *declone = de->clone();
    8.  
    9. de->setSelected(false);
    10.  
    11. declone->setPos(mouseEvent->scenePos());
    12. this->addItem(declone);
    13.  
    14. declone->setSelected(true);
    15. }
    16. QGraphicsScene::mouseMoveEvent(mouseEvent);
    17. }
    To copy to clipboard, switch view to plain text mode 

    This code is in class-child of QGraphicsScene. DiagramElement is child of QGraphicsItem.
    After cloning old and new items are selected and moving together.
    Old item is to stay in place and not be selected.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: QGraphicsScene - clone selected item by Alt+Move

    Hi,

    first just a note: avoid old c style casts. As to your problem (without testing), try to call QGraphicsScene::clearSelection() and then select the cloned item.

  3. #3
    Join Date
    Dec 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsScene - clone selected item by Alt+Move

    Thanks! I solved this problem wits methogs grabMouse() and ungrabMouse().

Similar Threads

  1. How change selected item rectangle on QGraphicsScene
    By xray2000 in forum Qt Programming
    Replies: 1
    Last Post: 18th May 2010, 16:43
  2. popupmenu for QTreeWidget's item when a particular item selected.
    By vinod sharma in forum Best Practices in Qt Programming
    Replies: 1
    Last Post: 22nd January 2010, 10:45
  3. Replies: 1
    Last Post: 20th January 2010, 08:38
  4. Move multi selected graphics items
    By tebessum in forum Qt Programming
    Replies: 1
    Last Post: 9th August 2007, 20:00
  5. Move window in Clone Mode
    By ultrabrite in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2006, 18:22

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
  •  
Qt is a trademark of The Qt Company.