Results 1 to 3 of 3

Thread: Copy - Paste QGraphicsItem on QGraphicsScene

  1. #1
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Copy - Paste QGraphicsItem on QGraphicsScene

    Hi All,

    I am developing a graphics editor where I draw a polygon on the QGraphicsScene from a polygon class derived from QGraphicsItem. I use the painter->drawLine() to connect all the points to draw the polygon in the paint().

    The co-ordinates are saved in my struct which has other properties in addition to the points. Now I need to copy and paste the polygon on the scene. I am picking up bits and pieces of QClipboard, QMimeData and QVariant, but I am yet to figure how best I can utilized these classes for my purpose. Am I heading in the right direction? Some pointers will be really helpful.

    Thanks in advance.

  2. #2
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Copy - Paste QGraphicsItem on QGraphicsScene

    Ok guys, I managed to figure out how this could be done.

    Implemented the keyPressEvent and handled as below
    Qt Code:
    1. if (pKeyEvent->key() == Qt::Key_C && pKeyEvent->modifiers() & Qt::ControlModifier)
    2. {
    3. listCopiedItems = this->selectedItems();
    4. }
    5.  
    6.  
    7. if (pKeyEvent->key() == Qt::Key_V && pKeyEvent->modifiers() & Qt::ControlModifier)
    8. {
    9. for(int i=0; i< listCopiedItems.count(); i++)
    10. {
    11. //the same implementation I did to construct the original item during creation after taking the co-ordinates from the original and did a setPos of the item to paste it with a small offset from the original item
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    Thanks everyone who tried to think about this.

    cheers!
    Last edited by pran; 16th February 2012 at 04:59.

  3. #3
    Join Date
    Jan 2012
    Posts
    66
    Thanks
    20
    Thanked 2 Times in 2 Posts
    Platforms
    Windows

    Default Re: Copy - Paste QGraphicsItem on QGraphicsScene

    That works, but I believe using QKeySequence would be a little better, e.g., QKeySequence::Cut, QKeySequence::Copy, and QKeySequence::Paste.

Similar Threads

  1. QGraphicsView Copy and Paste
    By stevel in forum Qt Programming
    Replies: 14
    Last Post: 13th January 2014, 07:57
  2. copy and paste
    By hubipet in forum Qt Tools
    Replies: 1
    Last Post: 17th July 2009, 06:19
  3. Copy-Paste files
    By Lele in forum Qt Programming
    Replies: 11
    Last Post: 4th April 2008, 14:15
  4. using cut(), copy(), paste()
    By systemz89 in forum Newbie
    Replies: 5
    Last Post: 18th December 2007, 14:47
  5. Copy/Paste in TableView
    By bronte in forum Qt Programming
    Replies: 2
    Last Post: 10th September 2006, 21:36

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.