Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How do?right click menu for each QTreeWidget Item
Qt 6.11 is out! See what's new in the release blog

How do?right click menu for each QTreeWidget Item

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 12.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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->setIcon(QIcon(":/aCool.png"));
      myAction->setShortcut(tr("Ctrl+M"));
      myAction->setStatusTip(tr("My action demo"));
      connect(myAction, SIGNAL(triggered()), this, SLOT(mySlot()));
      

      // Then add it to your treeWidget:
      treeWidget->addAction(myAction);

      @

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        You also need to set
        @
        treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
        @

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved