qt - I want to implement right click menus on QTWidgetItems -


I am working on a Uni project and our goal is to create a program that scans all IMG / video / movie files. Does the selected directory, stores them in a database and then shozs them in an organized manner (using QTreeWidgetItem). The program allows you to do some things like files are read, open them and so on. Now, the problem is that I want to right-click on one file and pop up a menu with many options such as Open Directory ...

I just do not know how this is correct. Click menu, I'm new in QT, I tried to create it:

  connect (tree widget, signal (item encrypted (QTreeWidgetItem *, int)), slot (open menu ( QTreeWidgetItem *, * integer)));  

I have tried to reset the item, but can not figure out how this is the right click and I think I am trying it wrongly.

I got inspired by:

  connect (tree widget, signal (itemWhite (Curie widgettum *, int)), this slot (OpenName Music (Curie widget) *, Int)));  

which executes a music file with a double click.

If you need more code parts then let me know :).

Edit after Andy Last comment to show new code:

  #include "affichagemusique.h" Afizzeux: :: Leire Music (QTreeWidgetItem * item, int column) {If (item-> Text (6)! = NULL) {Phonon :: MediaSource Source (item-> Text (6)); MediaObject- & gt; SetCurrentSource (source); MediaObject- & gt; Play (); }} Void AffichageMusique :: vueArtiste () {layout-> removeWidget (treeWidget); TreeWidget = new QTreeWidget (); QAction * pOpenDir = New QAction (tr ("Play Music"), tree widget); TreeWidget-> SetContextMenuPolicy (QT :: ActionsContextMenu); TreeWidget-> AddAction (pOpenDir); .......} // Later on Code Afzies Music :: pOpenDir () {QTreeWidget * treeWidget = new at QTreeWidget (); QTreeWidgetItem * QTreeWidgetI = treeWidget- & gt; Current item (); Ler Musik (Curie Visit I, 6); }  

Even if I remove the QTreeWidget * treeWidget = new QTreeWidget (); This is intended to work, I look at the menu when I right click, but when I click on the back then nothing happens.

In the QWidget class, you can find a method called:

  With zero setContextMenuPolicy (Qt :: ContextMenuPolicy policy)  

parameter: Qt :: ActionContextMenu (You can either set either by code or in QtDesigner.)

You can then create a QMenu like this:

  QTreeWidget * pTreeWidget = new QTreeWidget (); QAction * pOpenFile = New queue (tr ("open a file"), pContextMenu); PTreeWidget- & gt; SetContextMenuPolicy (QT :: ActionsContextMenu); PTreeWidget- & gt; AddAction (pTestCard);  

It's good to use this because you can reuse your actions in other menus, for example, in the main window menu ...

Hope That it will help you bit!


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -