Results 1 to 3 of 3

Thread: Adding contextmenu for QTreeWidgetItem .

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2012
    Location
    India
    Posts
    51
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Adding contextmenu for QTreeWidgetItem .

    Inside constructor
    ---------------------
    Qt Code:
    1. connect(ui.UserSpecificMaterial_treeWidget, SIGNAL(customContextMenuRequested(const QPoint &)),this, SLOT(ContMenu(const QPoint &)));
    To copy to clipboard, switch view to plain text mode 

    Inside slot
    -------------

    Qt Code:
    1. void MyContMenu::ContMenu(const QPoint &pos)
    2. {
    3. QTreeWidgetItem *item = ui.UserSpecificMaterial_treeWidget->itemAt(pos);
    4. if (!item)
    5. return;
    6. QMenu *menu = new QMenu(ui.UserSpecificMaterial_treeWidget);
    7. myAction = menu->addAction("Remove");
    8. myAction->setIcon(QIcon(QString::fromUtf8("Resources/Remove.png")));
    9. myAction->setShortcut(tr("Ctrl+D"));
    10. myAction->setStatusTip(tr("Remove the respective material from the User DB"));
    11. menu->exec(ui.UserSpecificMaterial_treeWidget->viewport()->mapToGlobal(pos));
    12. /---code to remove the item ./ }
    To copy to clipboard, switch view to plain text mode 

    In the above code whenever i right click on the QTreeWidgetItem it will show me the contextmenu having a single menuitem named Remove . What i want is whenever the user click on that remove menuitem at that time only it should remove that QTreeWidgetItem from the qtreewidget . but in the above code after rigtclick even if i click on any part of the UI it removes the respective QTreeWidgetItem from the treewidget , which i want to avoid .

    Thankss in advance .
    Last edited by riarioriu3; 25th September 2012 at 12:06.

Similar Threads

  1. QTreeWidgetItem have contextMenu ?
    By yunpeng880 in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2012, 03:56
  2. Replies: 11
    Last Post: 3rd March 2012, 22:21
  3. Replies: 5
    Last Post: 23rd September 2010, 13:58
  4. contextmenu with MDI
    By Thoosle in forum Qt Programming
    Replies: 1
    Last Post: 1st December 2006, 07:29
  5. ContextMenu
    By Naveen in forum Qt Programming
    Replies: 9
    Last Post: 21st February 2006, 10:54

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.