Results 1 to 2 of 2

Thread: Propper way to remove a QGraphicsItem by calling a QAction of the QGraphicView

  1. #1
    Join Date
    Dec 2008
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Propper way to remove a QGraphicsItem by calling a QAction of the QGraphicView

    Hey!

    i have these two functions in my QGraphicView class:
    Qt Code:
    1. void VideoWidget::contextMenuEvent(QContextMenuEvent * event) {
    2. QGraphicsItem *item = itemAt(event->pos());
    3.  
    4. QMenu menu;
    5. if (item&&item->flags().testFlag(QGraphicsItem::ItemIsSelectable))
    6. menu.addAction(tr("Remove Item"),this, SLOT(deleteDoor(item)));
    7. menu.addAction(tr("Add Door Selector"), this, SLOT(createDoor()));
    8. menu.addAction(tr("Add Cage"), this, SLOT(markCage()));
    9. menu.exec(event->globalPos());
    10. }
    11.  
    12. void VideoWidget::deleteDoor(QGraphicsItem *item) {
    13. scene.removeItem(item);
    14. }
    To copy to clipboard, switch view to plain text mode 

    This contextMenu is called, if you click somewhere in the View. If there is an item at the view's mouse click position the action "remove item" is added to the context menu. The Problem is, i dont know how to connect the QAction properly to the deleteDoor(QGraphicItem*) slot, because i need to pass the items pointer as a parameter, but the action only emits triggered()

    So What would you suppose is the best way to remove the item from the Scene by calling the context menu's action?

  2. #2
    Join Date
    May 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Propper way to remove a QGraphicsItem by calling a QAction of the QGraphicView

    QAction has a data field you may use to transfer some data through the action call

Similar Threads

  1. Replies: 7
    Last Post: 29th November 2010, 19:20
  2. Auto scroll in QGraphicview/QGraphicsecene?
    By jujose in forum Qt Programming
    Replies: 1
    Last Post: 13th May 2010, 11:00
  3. Replies: 2
    Last Post: 6th April 2010, 15:00
  4. my QGraphicView problem
    By irmakci in forum Qt Programming
    Replies: 3
    Last Post: 19th July 2008, 18:40
  5. Replies: 2
    Last Post: 28th June 2008, 16:31

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.