title: I want to implement right click menus on QTWidgetItems
body: <p>I am working on a uni project and our goal is to make a program that scans all img/video/movie files on a selected directory, stores them in a database and then shozs them in an organised way (using QTreeWidgetItem). Program allows you to do some stuff like read the files, open them and so on. Now, the problem is that I would like to Right click one of the files and pop up a Menu with many options like Open Directory, delete file...</p>
  
  <p>I just don' know how to make that right click menu, I'm kinda new to QT, I tried making this:</p>
  
  <pre><code>connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(openMenu(QTreeWidgetItem *, int)));
  </code></pre>
  
  <p>I tried redifining the itemClicked method but can't seem to find how to know if it's a right click and i think I might be trying it the wrong way.</p>
  
  <p>I inspired from this:</p>
  
  <pre><code>connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(opennMusic(QTreeWidgetItem *, int)));
  </code></pre>
  
  <p>which executes a music file on double click.</p>
  
  <p>If you need more code parts just let me know :).</p>
  
  <p>Edit after andy's last comment to show new code:</p>
  
  <pre><code>#include "affichagemusique.h"  
  
  
  
  
      void AffichageMusique::lireMusique(QTreeWidgetItem *item, int column)
  {
  
      if(item-&gt;text(6)!=NULL)
      {
      Phonon::MediaSource source(item-&gt;text(6));
      mediaObject-&gt;setCurrentSource(source);
      mediaObject-&gt;play();
      }
  }    
  
  
      void AffichageMusique::vueArtiste()
  {
  
      layout-&gt;removeWidget(treeWidget);
      treeWidget = new QTreeWidget();
      QAction* pOpenDir = new QAction(tr("Play music"),treeWidget );
      treeWidget-&gt;setContextMenuPolicy(Qt::ActionsContextMenu);
      treeWidget-&gt;addAction(pOpenDir);
  
  .......
  
  }    
  // later on on the code
  
      void AffichageMusique::pOpenDir()  
  {
  
      QTreeWidget * treeWidget = new QTreeWidget();
      QTreeWidgetItem * QTreeWidgetI= treeWidget-&gt;currentItem();
      lireMusique(QTreeWidgetI, 6);
  }    
  </code></pre>
  
  <p>Even if I remove the QTreeWidget * treeWidget = new QTreeWidget(); line it wont work, I see the menu when i right click but when I click PLay, nothing happens.</p>