How do?right click menu for each QTreeWidget Item

  • according to title how i can add a right click menu for each QTreeWidget Item

  • You need to create some actions in your dialog e.g. in the constructor:

    // In the header file:
    QAction *myAction;

    //Cpp file:
    myAction = new QAction(tr("&My Action"), this);
    myAction->setStatusTip(tr("My action demo"));
    connect(myAction, SIGNAL(triggered()), this, SLOT(mySlot()));

    // Then add it to your treeWidget:


  • You also need to set

    If you need to have different context menu for some of the items in the tree, you need to connect the itemSelectionChanged() signal to a slot where you remove/adds actions according to your needs.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.